Java Log Framework Ultimate Tutorial

Source: Internet
Author: User
Tags log4j

Overview

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.

Framework

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 officially introduced the Java logging API in the java.util.logging package, which is referred to as LOGJDK in this series of Tutorials. 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.

The LOGJDK framework provided in the JDK, as well as other third-party frameworks such as log4j, acls, 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 logjdk, 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 (logjdk)
    • In-depth analysis of Java's built-in log API (java.util.logging) (i)
    • In-depth analysis of Java's built-in log API (java.util.logging) (ii)
    • In-depth analysis of Java's built-in log API (java.util.logging) (iii)
    • In-depth analysis of Java's built-in log API (java.util.logging) (iv)
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

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: info-contact@alibabacloud.com 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.