Java has a lot of frameworks / APIs that help you do logging in your application:
- The Java API has java.util.logging package.
- Apache's Log4j.
- Apache's Commons Logging.
- SLF4J (logging Facade).
- 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
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.
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.
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.
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.
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.