3

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.

рüффп
  • 5,172
  • 34
  • 67
  • 113
David
  • 3,538
  • 9
  • 39
  • 50

2 Answers2

3

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.

Chris Dolan
  • 8,905
  • 2
  • 35
  • 73
  • Update: Pax-Logging 1.7.0 was released last week – Chris Dolan Oct 03 '12 at 20:42
  • Thanks But i see the newest release is 1.6.4.Link: http://team.ops4j.org/wiki/display/paxlogging/Download – David Oct 09 '12 at 21:27
  • Looks like the wiki is just out of date. Try this: http://search.maven.org/#search=pax-logging – Chris Dolan Oct 10 '12 at 01:13
  • Great. But do you know the document how to use it. how to make it understand logback.xml – David Oct 10 '12 at 16:07
  • Create a file `etc/org.ops4j.pax.logging.cfg` with contents like this: `org.ops4j.pax.logging.logback.config.file=${karaf.base}/etc/logback.xml` – Chris Dolan Oct 11 '12 at 12:23
  • I tried to make configuration and run, could not succeed. Anybody got it. My question http://stackoverflow.com/questions/24529660/how-to-make-pax-logging-to-use-the-loggback-config-instead-of-the-standard-log4j – Srikanth Hugar Jul 02 '14 at 11:56
0

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.

Olcay Tarazan
  • 931
  • 9
  • 12