What is the relationship between Slf4j-api, Slf4j-log4j12 and log4j?

Source: Internet
Author: User

Transfer from http://blog.csdn.net/tengdazhang770960436/article/details/18006127

In almost every jar package can see log4j figure, in a number of sub-engineering projects, SLF4J related conflicts from time to time to jump out to make you uncomfortable, then Slf4j-api, SLF4J-LOG4J12 and log4j what is their relationship? Let me share with you a little bit about what I know:

Slf4j:simple Logging facade for Java, a simple log facade for Java. Facade: The façade, the bottom point is that interface. He allows users to access different log systems in the project via SLF4J in their own preferences. More intuitively, the SLF4J is a data line, one end embedded in the program, the other end linked to the log system, so that the information in the program into the log system and recorded.

Therefore, the SLF4J portal is a collection of many interfaces, he is not responsible for the specific log implementation, only at compile time is responsible for finding the appropriate log system to bind. Specifically what interfaces, all defined in Slf4j-api. View Slf4j-api source code can be found, in addition to the public final class Loggerfactory class, are interface definitions. Therefore, the Slf4j-api essence is an interface definition.

A clearer description of the relationship between them:

When the system uses log4j as the log framework implementation of the call relationship:

First, the system contains SLF4J-API as the interface of log access;

At compile Slf4j-api in the public final class Loggerfactor class

The private final static void bind () method looks for a specific log implementation class binding, primarily through
Staticloggerbinder.getsingleton (); statement invocation

SLF4J-LOG4J12: Links the adapters in the middle of Slf4j-api and log4j. It implements the Staticloggerbinder interface in the Slf4j-apiz, so that the Slf4j-log4j12 Getsingleton () method is bound at compile time

Log4j: This is the specific log system. The output of the final log is reached by SLF4J-LOG4J12 initialization of the log4j.

What is the relationship between Slf4j-api, Slf4j-log4j12 and log4j?

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.