How to make logback (registration library) work with ServiceMix (recording in Karaf + ops4j)

I have been trying to make logback work with ServiceMix 4.3.0 (karaf 2.1.3) but failed. Is there anyone already successfully getting it to work? (with any version of serviceMix + slf4j + logback)

Here is my situation. I can make (Logback + slf4j + my application) work together in tomcat. Now I would like to make them work together in ServiceMix. ServiceMix uses OPS4J (org.ops4j.pax.logging) to provide slf4j (1.5.11). So, I have to use the slf4j provided by ServiceMix (I don't need to install the new slf4j package), then I installed the Logback Core module (0.9.20), the classic log module (0.9.20), jcl-over-slf4j (1.5.11) to make slf4j and logback work together. The installation was perfect with no errors. In my application, I have a piece of code to read the logback.xml from an 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 you run this code I always get this error:

java.lang.ClassCastException: org.ops4j.pax.logging.slf4j.Slf4jLoggerFactory could not be passed to ch.qos.logback.classic.LoggerContext .

Hence, I think the slf4j provided by ServiceMix does not work with the log library.

+3


source to share


2 answers


The as yet unreleased Pax-Logging 1.7 has log support. See https://github.com/ops4j/org.ops4j.pax.logging



What you are trying to do will never work with Pax-Logging, because Pax intentionally wraps the logger factory to allow the logging application to run. Instead, if you are using Pax-Logging 1.7 (someday), you will configure the log via the org.ops4j.pax.logging.cfg file that points to your logback.xml.

+3


source


I had a similar error and later noticed that I needed to re-register my imports in my osgi package. slf4j was imported after logback which is causing this error. When I removed this exception disappears.



0


source







All Articles