SLF4J is a simple and unified interface for various loging APIs, enabling end users to configure their desired loging APIs at deployment time.
To be exact, slf4j is not a specific logging system, but a facade of the user log system, allowing users to easily change their log system when deploying the final application. In the system development, unified according to the SLF4J API development, at the time of deployment, select a different log System package, can be automatically converted to a different log system. For example: Select the log system that comes with the JDK, You only need to put Slf4j-api-1.5.10.jar and Slf4j-jdk14-1.5.10.jar into the classpath, if you can not tolerate the JDK's log system, want to replace the log4j log system, only need to use slf4j-log4j12-1.5.1 0.jar Replacement of Slf4j-jdk14-1.5.10.jar (log4j jar and config file is also required)
SLF4J Get Logger object:
private static final Logger Logger = Loggerfactory.getlogger (Test.class);
Output log information:
Logger.debug ("Debug");
Log4j Get Logger object:
public class A {
private static Logger Logger = Logger.getlogger (A.class);
}
Here's a summary of SLF4J and log4j:
(1) Most people in the program will go to write Logger.error (exception), in fact, this time log4j go back to this exception tostring. The true wording should be logger (message.exception), and SLF4J would not make the programmer make the mistake.
(2) Log4j indirectly encourages programmers to use string addition, and SLF4J does not have this problem
You can use Logger.error ("{} Is+serviceid", Serviceid);
(3) The use of slf4j can be conveniently used to provide the various collective implementations of the jar. (similar to Commons-logger)
(4) Commons--logger and log4j merge is very convenient, SLF4J also provides a swing tools to help you complete this merge.
slf4j simple log façade with various log systems