Java Log Framework log system relationship detailed

Source: Internet
Author: User
Tags log4j
Java Log Framework log system relationship detailed

When we first contacted the Java Log framework and log system, I was completely confused about their relationship, and it was not clear what kind of system they were using. Make a good summary of their relationship today.

Before you explain the relationship, define two concepts:

1. Log system: The specific implementation of the log. The classic has log4j;jdk with java.util.Logging; There are also highly rated logback and so on that log4j authors have introduced.


2. Log frame: If only one log system exists, the log framework is completely unnecessary (Logback cannot be used independently), but it backfired. In order to solve the compatibility problem of multiple log systems, the log framework emerged. The mainstream log frame has commons-logging and sl4j.



Commons-logging is the log framework launched by Apache, Commons-logging is just a log interface designed to resemble the servlet and JDBC design in JDK. The mainstream journaling system implements the interface defined by the commons-logging, so that it looks at the common use of the log through the commons-logging, without having to use what kind of logging system is specifically used. COMMONS-LOGGING+LOG4J: A classic Log implementation program. appear in various frameworks. such as spring, WEBX, Ibatis, and so on. The direct use of log4j can satisfy our log scheme. But generally in order to avoid direct reliance on specific log implementation, is generally combined with commons-logging to achieve. Common code is as follows:

Import Org.apache.commons.logging.Log;

Import Org.apache.commons.logging.LogFactory;

private static Log logger = Logfactory.getlog (Commonsloggingtest.class);



As a universal reliable, fast and flexible log framework, Logback:logback is a complete implementation of the new log system as a log4j and slf4j. The official web site says it has excellent performance and is 10 times times faster to execute on critical paths and consumes less memory than log4j. See the specific advantages:

Http://logback.qos.ch/reasonsToSwitch.html

Logback must be used in conjunction with SL4J. Since Logback and sl4j are the same authors, their compatibility is self-evident. However, sl4j faces compatibility issues with other logging frameworks and logging systems.


1. JCL-OVER-SL4J: It rewrites the commons-logging API and shifts all log output to sl4j. This avoids the problem of two sets of log frames coexisting. Because Jcl-over-slf4j and the original commons-logging have exactly the same APIs, the two cannot coexist.


2. SL4J-*12: Concrete such as sl4j-lo4j12 its implementation of the SL4J interface and the log into the log4j.


A picture wins thousand words:


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.