History
Over time, several logging frameworks were created by different parties for Java. Therefore, Java libraries were written using different logging frameworks. This was not an issue if an application used a unique logging framework, but when they started to reference each other's libraries, it became a different game.This is why logging interfaces were created to bridge these multiple logging frameworks. The purpose is to centralize logs calls to one framework.
Log4J
Log4J is a login framework which was created before Sun Microsystems introduced its own logging framework (called JUL of JDK Logger) in Java 1.4. Many developers chose to stick to Log4J, rather than move to the JDK Logger, because it contained better features.However, after logging interfaces were created, some people became wary of Log4J, because it is very low level. They were using Java libraries using different frameworks. Many decided to use logging interfaces, rather than directly implementing Log4J in their code.
Java Logging API (JUL or JDK Logger)
This logging framework is available in the java.util.logging package since Java 1.4. It can be extended via the API. Many developers complained about too many logging levels: FINE, FINER, FINEST where DEGUG would have been enough, or missing features which Log4J was already offering.Some developers also complained this framework was not well designed for web containers. For example, some containers, such as Tomcat, provided access to a common root logger shared by multiple applications. If a filter was set on it, it was set for all applications.
I have never understood why it was necessary to use anything other than log4j, which solved logging elegantly and simply. The Sun JDK 1.4 implementation of logging in particular seemed like an imitation that offered no real improvement. I use log4j in my own applications and have no plans to change.
ReplyDeleteFacade frameworks exist because people who write libraries often unthinkingly include specific loggers in their code. You, the application programmer, may have chosen Log4J for your project. Now, you choose a library that uses java.util.logging. If you do nothing, you will end up with two sets of log configuration files, and two sets of log files.
ReplyDeleteIn this case, you can use a bridge library with classes named the same as the java.util.logging classes. These forward JUL calls to your logger.
If you are writing a library, please use a facade system so the application programmer can choose whatever real logger he wants.
Log4J is old hat, effectively unsupported now, and noticeably slower than Logback.
ReplyDeleteYou can smooth migration to a better logger by using the SLF4J logging facade with the SLF4J Log4J target, then gradually migrate all you logging statement to SLF4J facade Loggers; when completed you can choose any SLF4J logger target, including custom ones.
SLF4J has provision to pass thread level key/value pairs and markers, these are useful for extra logging values and much more flexible log filtering; Logback supports these features.
Logback also has wonderful features like system property use by the logging configuration XML (e.g. to reference a logger path relative to the Tomcat folder) and bundles rolling logger file features like automatic zipping up of old log files.