SLF4J and log4j

Source: Internet
Author: User

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

Related Article

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.