Log4j works with Apache commons Logging

Source: Internet
Author: User

Apache's common logging is a high-level log framework that does not implement real log writing capabilities, but relies on other log systems such as log4j or Java. util. logging. You can use the configuration file to set whether to use log4j or Java. util. logging.

Java. utl. Logging is used by default. If you want to use log4j, You need to configure it in three steps,
1. Create a log4j configuration file, such as log4j. proiperties:
Log4j. rootlogger = debug, A1
Log4j. appender. A1 = org. Apache. log4j. leleappender
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
Log4j. appender. a1.layout. conversionpattern = %-4r %-5 p [% T] % 37C % 3x-% m % N
These configurations allow log4j to output log information to the console. For details about log4j configuration, see the Apache log4j documentation.

2. Create a configuration file for commons-logging, commons-logging.properties:
Org. Apache. commons. Logging. logfactory = org. Apache. commons. Logging. impl. log4jfactory
Org. Apache. commons. Logging. impl. log4jfactory is a logfactory derived class implemented by commons-logging for log4j.

3. Write in the Code:
Log = logfactory. getlog (...);
Then you can use log to directly write log information, such
Log. debug ("...")
Log. Error ("...");
...

Note: Both configuration files must be under classpath.

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.