logback in spring-OSGI with pax-runner

2019-04-15 11:45发布

问题:

We are running OSGI bundles with pax-runner. We are logging using logback over slf4j.

The problem is logback tries to look for logback.xml in classpath, but in pax-runner where should I place logback.xml so that pax-runner configure logback accordingly?

I have tried with JoranConfigurator to load logback.xml which is included in bundle classpath, but it assumes classpath as the container in which the bundle is running (in my case it is runner folder where all the bundle jars are placed).

Any help would be appreciated.

Thanks in advace.

回答1:

The usual approach would be to create a fragment bundle that is attached to the logback bundle and put logback.xml in there. Fragment bundles "extend" other bundles, so their contents are available to the classloader of the host bundle. This way, logback can find logback.xml in the classpath.



回答2:

Another solution would be to configure logback to read the configuration file from outside the classpath.

This can be done by setting VM options -Dlogback.configurationFile=/dir/conf/logback.xml