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.

7 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. Welcome to mmoggg website to buy WoW Gold Kaufen, offer a lot, of course, Diablo 3 Gold or Cheap Diablo 3 Gold and RS Gold, to be purchased at any time, at any time shipment, and look forward to your visit!

    ReplyDelete
  4. 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
  5. 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
  6. Visio Standard 2010 Download offers modern and intuitive diagramming tools to transform complex ideas into aha moments and get everyone on the same page with less time and effort. A diverse set of pre-drawn shapes, pictures, and templates, and new automatic drawing tools make visualization easier than ever.
    Microsoft Visio Professional 2010 Download provides real-time data connections that allow you to create dynamic, data-driven diagrams easily shared through a browser. It also provides more templates and shapes for engineering, finance, operations, sales, and human resources professionals.

    ReplyDelete
  7. Nice article, thanks for the information. It's very complete information. I will bookmark for next reference
    jaring futsal | jaring golf | jaring pengaman proyek |
    jaring pengaman bangunan | jaring pengaman gedung
    http://www.jual-jaring.blogspot.com/
    http://www.agen-jaring.blogspot.com/
    http://www.pancasamudera-safetynet.blogspot.com/
    http://www.toko-jaring.blogspot.com/
    http://www.pusat-jaring.blogspot.com/
    http://jualjaringpengaman.blogspot.com/
    https://pancasamudera.wordpress.com/
    https://pasangjaringfutsal.wordpress.com/
    https://jualtambangmurah.wordpress.com/
    https://tokojaring.wordpress.com/
    https://jualjaringfutsal.wordpress.com/
    https://jaringfutsal.wordpress.com/


    ReplyDelete