Tuesday, December 28, 2010

Logging with SLF4J and LogBack in Eclipse Application (with Hibernate)

During my EMF persistence adventures with CDO 3.0, Teneo 1.1.2, and Hibernate 3.3.2 there's something bugging me: The Hibernate bundle from Elver.org includes several out-of-context dependencies SLF4J API, SLF4J NOP implementation, SLF4J Log4j implementation and Log4j.

Bundling logging JARs is already strange enough, but the provided Log4j is of version 1.2.8 while SLF4j Log4j 1.5.8 requires at least Log4j 1.2.12. Even more is it bundles SLF4j NOP implementation, why???

Since it's embedded, it makes it impossible for me to use the embedded SLF4j and Log4j for my own purposes.

So I decided to fix things a bit. This is quite unproductive, but I guess it's an okay exercise.

First I have to delete several files from the exploded org.hibernate_3.3.2.201005082216 plugin:

  1. slf4j-api-*.jar
  2. slf4j-log4j-*.jar
  3. slf4j-nop-*.jar
  4. log4j-*.jar
Deleting these files "saves" about 400 KB of space. :-) Not bad.

Then I have to change the META-INF/MANIFEST.MF of the Hibernate plugin:

Edit the Bundle-ClassPath from:

Bundle-ClassPath: antlr-2.7.6.jar,c3p0-0.9.1.jar,commons-collections-3
.1.jar,ehcache-1.2.3.jar,hibernate3.jar,hibernate-annotations.jar,hib
ernate-commons-annotations.jar,hibernate-entitymanager.jar,javassist-
3.11.0.GA.jar,jta-1.1.jar,log4j-1.2.8.jar,slf4j-api-1.5.8.jar,slf4j-l
og4j12-1.5.8.jar,slf4j-nop-1.5.8.jar

To:

Bundle-ClassPath: antlr-2.7.6.jar,c3p0-0.9.1.jar,commons-collections-3
.1.jar,ehcache-1.2.3.jar,hibernate3.jar,hibernate-annotations.jar,hib
ernate-commons-annotations.jar,hibernate-entitymanager.jar,javassist-
3.11.0.GA.jar,jta-1.1.jar

With the unnecessary cruft removed, it's time to add SLF4j and Logback plugins to the target platform. Get these from Orbit:

  1. ch.qos.logback.classic_0.9.24.v20100831-0715.jar
  2. ch.qos.logback.core_0.9.24.v20100831-0715.jar
  3. ch.qos.logback.slf4j_0.9.24.v20100831-0715.jar
  4. org.slf4j.api_1.6.1.v20100831-0715.jar
  5. org.slf4j.jcl_1.6.1.v20100831-0715.jar

In total they are 619 KB. Not bad for a shared logging system. :-)

Now remove/exclude org.apache.commons.logging plugin from your target platform because org.slf4j.jcl plugin replaces it.

Done! That's it. SLF4j and Logback providing nice logging implementation inside the Eclipse platform application.

A nice side effect is that log4j.properties is no longer needed, because Logback works fine without configuration.
But you can also configure Logback.

Also checkout Logging in OSGi Applications by ekkes-corner for more thorough explanation.

4 comments:

  1. Thanks very much for sharing this valuable information. I would definitely like.

    ReplyDelete
  2. You neglected one more thing..Buy Cheap RS Gold. "Any software surroundings you can imagine". :N With resources such as EMF along with M2T, you can target just about any system. In the forums , you're thinking about very revealing interior help however simply were required to mention it while there is a Buy MapleStory Mesos whole world of probable here.
    Response

    ReplyDelete
  3. Since the outbreak of fully open because deterrence is still getting bigger, so the hunter must select the control you. We can not waste our the vendetta decisive badge escape from his spider web. Do not open the outbreak of speed because the energy is gone. Smokescreen opened decisive BIU, revenge killings in the body, buy wow gold 3DOT BIU up very hurt.

    ReplyDelete
  4. This is how enjoyable checking out Cheap Guild Wars 2 Gold.Vibrant occasions compared to. traditional quests Buy D3 Gold. But after a couple of occasions is actually however much too soon becomes apparent Game News

    ReplyDelete