It is recommended to use SLF4J (simple Logging facade for Java) as the api,slf4j of a log system, which allows end users to use their desired log system when deploying their applications.
1 SLF4J Advantages
Compared to using Apache commons-logging or using log4j directly, SLF4J provides an advanced feature called parameterized logging, which can significantly improve the performance of log statements in cases where logging is configured to shut down.
Log.debug ("Found {} Records matching filter: ' {} '", records, filter);//slf4j
Log.debug ("Found" + Records + "Records matching filter: '" + filter + "'");//log4j
It can be seen that the advantages of SLF4J are: more simple and easy to read; When the log level is insufficient, the cost of string concatenation is less, and the ToString method of the object (Records/filter) is not called.
SLF4J after 1.6.0, but also support the exception stack printing, as the last parameter passed in, basically meet the common print scene of the log.
Log.error ("Failed to format {}", S, e);
2 Note the inheritance relationship between logger
The inheritance of logger is implemented by naming.
The child logger inherits the Appender of the parent logger by default, adding them to their appender, and the additivity= of the parent logger is no longer inherited unless the Appender "false" is added.
The child logger inherits the output level of the parent logger only if it does not define the output level itself.
SLF4J and log4j