log4j, common-logging, slf4j relations

Source: Internet
Author: User

Recently because of the project reasons, seriously studied the log4j related content, mainly from the Internet to find information, as well as tracking the original code.   about how to use, there is a lot of information on the Internet, here do not do specific introduction. The relationships of these tools are described below.  LOG4J is the most powerful and popular log tool, with many other logging tools, such as Logback (said to be better than log4j, built by the same squad), and Java.util.logging.Logger. In order to unify a variety of log tools, Common-logging appeared, the following is its all the source code files: The structure is clear: 1, log defines a unified abstract interface 2, Impl encapsulated in a variety of existing logging tools, such as Log4jlogger is log4j encapsulation, Jdk14logger is the encapsulation of Java.util.logging.Logger, Avalonlogger/logkietlogger is another package of log tools. Finally, Simplelog is the Logger of Common-logging's own implementation, the function is simple, the other tools can not be used when the final solution. 3, Logfactory is the external interface, using the way: Logfactory.getlog (Test.class). The default implementation is Logfactoryimpl in the diagram.  SLF4J is similar to the above common-logging function and positioning, by a basic package SLF4J-API defines a unified log interface Logger, factory interface loggerfactory. Package Slf4j-log4j12 is  slf4j to log4j (version 1.2?). ) of the package, wherein Log4jloggeradapter is packaged with Org.apacha.log4j.Logger, inherited from Org.slf4j.logger,log4jloggerfactory is the corresponding factory method. Here are two jar packages that need to be used together.   Our project, is a more tangled situation, all three exist, specifically SLF4J realized the common-logging two interfaces, that is, Slf4jlog realized Org.apache.commons.logging.Log, factory method Slf4jlogfactory inherited the Org.apache.commons.logging.LogFactory. Personally feel that this is too complicated, not necessary, do not know to remove the  SLF4J's dependence.   about log4j, the default profile is Log4j.properties (or log4j.xml, but I'm not very fond of using it). Some of the jar packages referenced often already contain the file (bad rating) and may overwrite our own configuration file and need to be removed manually. You can also use the system variable log4j.configuration to specify a profile address instead of using the default file address.  commons-logging has a default configuration file Commons-logging.properties, which is optional, which is convenient. It is possible to set the variable priority, which resolves multiple configuration file selection issues. I think that if you can also set the  log4j.configuration in the commons-logging.properties, so that the effect is perfect. However, there is no.   

Log4j, common-logging, slf4j relationship

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.