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.
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. Through the SLF4J-LOG4J12 initialization log4j, the final log output is reached.
What is the relationship between Slf4j-api, Slf4j-log4j12 and log4j?