[英]Logback include fragment in OSGi container
I have a project a-conf
with src/main/resources/logback/conf/a/CommonAppenders.xml
file: 我有一个项目
a-conf
用src/main/resources/logback/conf/a/CommonAppenders.xml
文件:
<included>
<appender name="FILE" class="FileAppender" />
</included>
Also i have another project a-runable
with logback.xml
config which imports CommonAppenders.xml
: 另外我还有另一个可以通过
logback.xml
配置a-runable
项目, logback.xml
配置导入CommonAppenders.xml
:
<configuration>
<!-- this is classpath import -->
<include resource="logback/conf/a/CommonAppenders.xml" />
...
</configuration>
I can compile a-runable
in standalone jar with all dependencies ( a-conf
is one of them) included or as an OSGi bundle. 我可以在包含所有依赖项的独立jar中编译
a-runable
( a-conf
是其中之一)或作为OSGi捆绑包。 When i run standalone app everything is ok - log files appears as specified in CommonAppenders.xml
. 当我运行独立应用程序时,一切正常,日志文件将按照
CommonAppenders.xml
指定显示。 But when i run OSGi container no log files are created. 但是,当我运行OSGi容器时,不会创建任何日志文件。 I think logback just cannot include resource from classpath because every bundle in OSGi container has its own classloaders (logback uses
ClassLoader.getResource()
to include file). 我认为logback不能包含类路径中的资源,因为OSGi容器中的每个捆绑软件都有自己的类加载器(logback使用
ClassLoader.getResource()
包含文件)。
I've checked Export-Package: logback.conf.a
in a-conf.jar/META-INF/MANIFEST.MF
(this is done by maven bundlor plug-in) - it is ok. 我已经在
a-conf.jar/META-INF/MANIFEST.MF
检查了Export-Package: logback.conf.a
(这是由maven bundlor插件完成的)-可以。 Added Import-Package: logback.conf.a
to a-runable
with no effect. 已将
Import-Package: logback.conf.a
添加到Import-Package: logback.conf.a
a-runable
,但没有任何效果。
I have no ideas what can i do (no code to change, just configs). 我不知道该怎么办(无需更改代码,只需进行配置即可)。 Any help would be welcome.
任何帮助都将受到欢迎。
PS I've found similar problem here , but logback.xml
is already in classpath and its own appenders works fine. PS我在这里发现了类似的问题,但是
logback.xml
已经在classpath中,并且它自己的附加程序可以正常工作。 Also i do not have any FileNotFoundException
s in existing logs. 另外,我在现有日志中没有任何
FileNotFoundException
。
By default, I believe Logback's startup errors are simply dropped if you don't configure a listener (but I may be remembering wrong). 默认情况下,如果您未配置侦听器,我相信Logback的启动错误只会被丢弃(但是我可能会记错了)。 The key is likely that a-conf needs to be a Fragment of the bundle that contains logback.jar.
关键可能是a-conf必须是包含logback.jar的捆绑软件的片段。 That's what I've done for my bundle that has some homebrew appenders.
这就是我为具有一些自制酿造器的捆绑包所做的工作。
If you want to see a setup where Logback is pre-configured to output its startup errors to the OSGi container, take a look at Pax-Logger 1.7 - https://github.com/ops4j/org.ops4j.pax.logging/tree/master/pax-logging-logback 如果要查看将Logback预配置为将其启动错误输出到OSGi容器的设置,请查看Pax-Logger 1.7- https://github.com/ops4j/org.ops4j.pax.logging/树/主/ pax-logging-logback
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.