Commons-logging + Log4j Getting Started Guide (log4j)

Source: Internet
Author: User
Tags log4j

 

 

How can we make Log4j play its role? The answer is simple. You only need to meet the requirement that "jar packages with Log4j in classpath ". As mentioned above, commons-logging will automatically discover and apply Log4j. So as long as it exists, it plays a role. (Does it exist? Naturally, it does not work. commons-logging will select other log implementation classes .)

Note: the configuration file log4j. properties is required for Log4j. If the configuration file does not exist in the classpath, or the configuration is incorrect, a running exception is thrown.
In this way, to correctly apply Log4j to output log information, the role of log4j. properties is very important. Fortunately, this file has a general template and can be used by copying a copy (slightly modified. Almost every Java project directory contains a log4j. properties File. You can download the source code of several open-source Java projects. At the end of this article, we also attached a template-type log4j. properties file, which can be directly copied and used, or modified as needed. The log4j. properties file will be introduced later.
Here, by the way, we will be prompted: If you don't need to use commons-logging and use Log4j separately, the operation will be a little more troublesome, because Log4j requires a little more initialization code (compared to commons-logging ):

 


1 import org. apache. log4j. Logger;
2 import org.

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.