Java Log Framework Ultimate Tutorial

Source: Internet
Author: User
Tags log4j


For modern Java applications, as long as they are deployed to a real production environment, the importance of their logs is self-evident, and it is hard to imagine that applications without any logging capabilities are running in a production environment. The log API provides a variety of features, including error messages, status information, debug information, and execution time information that are generated when the program is run. In a production environment, logs are an important basis for finding the source of the problem, and all the important information that is generated when the application is run should be logged through the log API.

Many Java developers are accustomed to using SYSTEM.OUT.PRINTLN, System.err.println, and Printstracktrace methods of exception objects to output relevant information. These are simple to use, but the amount of information generated is relatively small, and it has not been preserved for a long time, and these methods do not provide effective help when problems need to be found for reasons of application. None of these should appear in the formal production environment code, but instead use the Java log framework instead. The use of the log framework does not add a lot of complexity, but the benefits offered are significant.


Logging is an essential feature of Java application development and does not include logging-related APIs and implementations in earlier versions of the JDK. Starting with JDK 1.4, SUN's official introduction of the Java Logging API in the java.util.logging package, referred to as JUL. In addition, the Java community has developed and contributed a lot of open source, excellent log APIs and implementations. Among them, there are log4j, Logback, Log4j2, Apache Commons Logging (ACL), slf4j and so on.

Both the JUL framework provided in the JDK, and the log4j, ACLs, and other third-party frameworks are designed to meet the functional requirements that can easily and clearly record log information in Java applications. However, there are still great differences between these frameworks in the design ideas and concepts, which directly lead to their market share in the Java field. In addition, these popular log frames can be divided into two factions according to their level differences and functional differences:

    • Java Log Implementation framework: such as JUL, log4j, Logback, log4j2
    • Java Log Wrapper framework: such as ACLs, SLF4J, Log4j2

Log4j2 is more special, it is both an implementation framework and a package framework.

The JDK platform and third parties offer so many excellent frameworks and options for this common need for logging information logging in Java applications. For novice Java, how to choose a log framework that fits the current project is obviously a problem to solve. As an experienced man, I decided to make every effort to write a Java log framework related to the ultimate tutorial in the case of the director of the public home. Taking into account the flow and functional characteristics of each framework, this tutorial will give priority to the frameworks listed below, which may be adjusted later depending on the situation.

Java.util.logging (JUL)
    • In-depth analysis of Java's built-in log API (java.util.logging) (i)

Log4jlogbackapache Commons Logging (ACL) sfl4jlog4j2 Summary

Logging is an essential functional requirement for any Java application, but due to historical reasons, there are many good log frameworks in the Java field, and Java novices are often confused about the situation. As an experienced man, I hope that on the basis of absorbing, write a Java log framework of the ultimate tutorial, to help readers easily grasp the Java log records of all the knowledge points and skills.

Java Log Framework Ultimate Tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.