Question

I am trying to make logback works with ServiceMix 4.3.0 (karaf 2.1.3) but not successful. Is there anybody already successfully make it work? (with any version of serviceMix + slf4j + logback)

Here is my situation. I am able to make (Logback + slf4j + my App) work together in tomcat. Now i would like to make them work together in ServiceMix. ServiceMix is using OPS4J (org.ops4j.pax.logging) to provide slf4j (1.5.11). So, i have to use slf4j that provided by ServiceMix (i dont have to install new slf4j bundle), next i installed Logback Core Module (0.9.20), Logback Classic Module (0.9.20), jcl-over-slf4j (1.5.11) in order to make slf4j and logback working together. The installation was fine, no error. In my application, i have a code snippet to read logback.xml from external folder.

fis = new FileInputStream(System.getProperty("logconf") + "/logback.xml");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(fis);

but whenever running this code, i always get this error:

java.lang.ClassCastException: org.ops4j.pax.logging.slf4j.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext.

Hence I think slf4j proviced by ServiceMix doesn't work with logback library.

Was it helpful?

Solution

The not-yet-released Pax-Logging 1.7 has Logback support. See https://github.com/ops4j/org.ops4j.pax.logging

What you're trying to do will never work with Pax-Logging because Pax intentionally wraps the logger factory to allow runtime injection of the logging provider. Instead, if you use Pax-Logging 1.7 (someday) then you'll do the logback configuration via the the org.ops4j.pax.logging.cfg file, which points at your logback.xml.

OTHER TIPS

I got similar error and later noticed that I need to reorginize my imports in my osgi bundle. slf4j was imported after logback which causes this error. When I removed that exception is gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top