views:

283

answers:

5

Hey to all Java has a lot of frameworks / APIs that help you do logging in your application:

  1. The Java API has java.util.logging package.
  2. Apache's Log4j.
  3. Apache's Commons Logging.
  4. SLF4J (logging Facade).
  5. jLo. and many many more...

I've always used the log4j library, i found it sufficient most of the time, and extensible when i needed more control.

Anyone who had experience with more than one framework can share his experience? when is it better to use one framework over the other and from application architecture point of view? Why would i prefer one over other?

Thanks

A: 

This question seems identical to 354837.

The simple answer is that you'd go for Commons Logging if you're writing a library that may be dropped into applications where you have no control over the logging, one of the other choices if not. I personally use CL in all cases, simply because it's common -- I don't need to remember the differences between frameworks.

kdgregory
Wow, a downvote nearly 6 months after answering ... did someone have a bad experience with Commons Logging, or is someone just an asshole ... we'll never know, because s/he couldn't be bothered to comment.
kdgregory
I wasn't the person downvoting you but I'm quite a bit allergic against commons.logging... I was using it exclusively until about three years ago and switched *all* the code under my fingers over to SLF4J in the meantime. I'd still consider a downvote of your answer crude, especially without a comment, but some people are like that :(
Huxi
+9  A: 

Commons Logging is source of strange classloading problems. Avoid it if you can. I prefer log4j when developing application. If you develop library/framework and you don't want to enforce logging library, choose slf4j.

Peter Štibraný
And let's not forget that the official nickname for Commons Logging is "clogging".
Damien B
A: 

Whatever the official position is "log4j" is the standard logging framework.

It works well and has been around for a while. Its the most deployed logging framework used by thousands of apps and packages. Its also the logging framework most likely to appear on a developers CV.

Stick with log4j there is no good reason to try anything else.

James Anderson
Huxi
+4  A: 

If its new code i'd start with slf4j, since it provides the simplest way to switch between the underlying logging api's by just including the required slf-[logging_api].jar in the classparth of your app. For example - if you start with log4j you still have to configure a Conole logger in a log4j.xml to see your logging output, with slf4j you just include the slf4j-simple.jar.

emeraldjava
+2  A: 

Logback is a rewrite of log4j. If you like log4j, you should like logback even better.

Moreover, logback is a native implementation of the SLF4J API which means that is you are using logback, then you are actually using SLF4J. Thus, if for any reason you wish to switch back to another logging framework, be it log4j or j.u.l. you can do so by replacing one jar file with another.

Ceki