Log4j 2.0 and SLF4J and the never ending future of java logging frameworks

Adam Gent picture Adam Gent · Aug 23, 2012 · Viewed 14.3k times · Source

So I just found out today that Log4J 2.0 is now actively being developed, there is an alpha version and it is said to replace logback.

Right now in my app I have close to 4 maybe more logging frameworks:

  • Java Util Logging
  • log4j
  • slf4j
  • logback (ignored thanks to a maven provided hack)
  • commons logging (ignored thanks to a maven provided hack)
  • And tomcat has its own JULI adapter

I have been using log4j (1.2.x) because frankly I just haven't needed the features of the newer guys but I have been tempted lately to switch to SLF4J and mainly because I don't want to have rewrite my complicated log4j configurations files to a new format (logback).

Now my question is in terms of what I should code against is SLF4J the right choice for the future given log4j 2.0.

It seems like I should just stick with old log4j (1.2.x) as it is the lowest common denominator?

UPDATE: on further examination of log4j 2.0 while very similar it appears the configuration is not backward compatible with log4j 1.2. Looks like logback is the best choice.

Answer

Ceki picture Ceki · Aug 23, 2012

Disclaimer: I am the founder of log4j, slf4j and logback projects but unaffiliated with log4j 2.0.

As I understand it, notwithstanding its name, log4j 2.0 is very different than log4j 1.x. As far as the user API is concerned, log4j 2.0 is largely incompatible with log4j 1.x. Log4j 2.0 provides an adaptation layer for log4j 1.x which at present time (2012-08) is undocumented.