I have a project a-conf
with src/main/resources/logback/conf/a/CommonAppenders.xml
file:
<included>
<appender name="FILE" class="FileAppender" />
</included>
Also i have another project a-runable
with logback.xml
config which imports 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. When i run standalone app everything is ok - log files appears as specified in CommonAppenders.xml
. But when i run OSGi container no log files are created. 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).
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. Added Import-Package: logback.conf.a
to a-runable
with no effect.
I have no ideas what can i do (no code to change, just configs). Any help would be welcome.
P.S. I've found similar problem here, but logback.xml
is already in classpath and its own appenders works fine. Also i do not have any FileNotFoundException
s in existing logs.
By default, I believe Logback's startup errors are simply dropped if you don't configure a listener (but I may be remembering wrong). The key is likely that a-conf needs to be a Fragment of the bundle that contains 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