This is the 10th day of my participation in the August Text Challenge.More challenges in August

Java Logging Framework evolution history

Log4j

One of the first logging frameworks implemented by the Apache foundation, prior to Java1.4, was the only alternative. Who would have thought that before Java1.4, the JDK didn’t have logging built in! .

JUL(jdk-logging)

In 2002, with the release of Java1.4, Sun introduced its own logging library, J.U.L(jdk-logging). But it basically mimics Log4j’s implementation.

JCL(commons-logging)

JUL, after all, comes with the JDK and is widely used. There are other log components, such as SimpleLog. At this point, if someone wants to switch to another logging component, such as Log4j to JUL, because the API is completely different, they need to change the code.

To decouple the Logging interface from the implementation, Apache has introduced JCL, Apache Commons Logging. JCL defines only a set of logging interfaces, implemented by Log4J or JUL. JCL implements logging based on dynamic binding, and you only need to write code using the jCL-defined interface. When the program actually runs, it checks the implementation in the CLASspath, so you can choose whether log4J or JUL implements logging.

Slf4j

In 2006, Ceki Gulcu, the author of Log4j, left Apache and came up with a j.C.L-like interface class called Slf4j. The reason is that the author feels that the design of the J.C.L interface is not good, and it is easy for developers to write code with performance problems. Slf4j, as a set of standard interfaces, can achieve seamless docking with a variety of implementation frameworks. It is also a common log integration method nowadays.

Logback

After Slf4j was developed, Ceki Gulcu developed Logback as the default implementation of Slf4j. Logback surpasses all existing logging implementation frameworks in terms of functional integrity and performance.

Logback is an updated version of Log4j and is currently divided into three target modules:

  • Logback-core: Core module, which is the base module of the other two modules
  • Logback-classic: an improved version of Log4j, with a full implementation of the SLF4J API that allows you to easily switch to other Logging systems such as Log4j or JDK14 Logging
  • Logback-access: The access module integrates with the Servlet container to provide access to the diary over Http and is an integral part of Logback

Logback has more advantages over Log4j:

  • Faster execution speed
  • More extensive testing
  • Logback-classic implements SLF4J quite naturally
  • Use XML configuration files or Groovy
  • Automatically reloads the configuration file
  • Gracefully recover from I/O errors
  • Automatically clear old log archive files
  • Automatically compress archive log files
  • Cautious mode
  • Lilith
  • Conditional handling in configuration files
  • Richer filtering

Log4j2

In 2012, Apache rewrote Log4j to implement Log4j2. It has all the features of Logback in terms of functionality. == is the most complete logging framework available. = =

Classification of log

Interface facade log framework

Only API definitions are provided, but no implementation is provided. The goal is to provide standardized usage for the application layer. It’s called interface oriented programming. SLF4J, JCL

Implement a record-like logging framework

A log implementation class that collects and manages logs. Log4j, JUL, Log4j2, Logback

Bridging class

When a variety of log implementation frameworks are mixed, it is necessary to use the bridge class to transform the log, and finally unify the log into one output. Slf4j-jdk14, slf4j-log4j12, log4j-slf4j-impl, logback-classic, slf4j-jCL, jul-to-slf4j, log4j-over-slf4j, icl-over-slf4j, log4j- to-slf4j