Tuesday, September 4, 2007

Switching from LOG4J to SLF4J

I have already mentioned that I was going to give SLF4J a try. Now, I am going to summ up what it took for me to switch from LOG4J to SLF4J logging library in a few items for maven based web project:
  1. discarded dependencies: commons-logging (1.0.4) and log4j (1.2.8)
  2. added new dependencies: slf4j-api (1.4.3), logback-core (0.9.8) and logback-classic (0.9.8)
  3. added one more dependency: jcl104-over-slf4j (1.4.3)
  4. created a logging configuration file logback.xml in the root of classpath (replacement for log4j.properties)
That's it!
Of course, I had to modify java code so that it uses Logger instead of Log now.

As for the item #3 it deserves a little bit more clarification. Since my final war is going to be deployed in Tomcat bundled with several other jar libraries (mostly apache commons, Spring and great Stripes framework) then dependency on JCL still resists. The solution to this problem is jcl104-over-slf4j.jar which implements the public API of JCL but using SLF4J underneath [see slf4j manual].