Using Commons-logging's Notes

Source: Internet
Author: User
Tags log4j

Commons-logging is a jarkata that encapsulates a variety of Java logs, such as log4j, JDK log, Logkit, Nooplog, and Simplelog.

Eclipse can use the LOG4E plug-in, quickly insert the Logger object, set the log4e template for the commons-logging template on it. And at the same time put commons-logging and log4j jar packs as far as the engineering classpath.

In a class MyClass code editing page, right-click Select LOG4E, select Declare logger, that is, add the following code on the basis of the source code, as follows: Import Org.apache.commons.logging.Log;
Import Org.apache.commons.logging.LogFactory;

/** */ /**
* Logger for this class
*/
Private static final Log logger = Logfactory.getlog (MyClass. Class);

Need to add log4j.xml files in the SRC directory, as follows: XML version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE log4j:configuration SYSTEM "LOG4J.DTD" >

< log4j:configuration >

<!--config console= "STDOUT"/-->
< Appender name = "STDOUT" class = "Org.apache.log4j.ConsoleAppender" >
< layout class = "Org.apache.log4j.PatternLayout" >
< param name = "Conversionpattern" value =%d{hh:mm:ss. SSS}%-5p [%t]-%m "/>
</Layout >
</Appender >

<!--config debug= "Debug"/-->
< Appender name = "Debug_log" class = "Org.apache.log4j.RollingFileAppender" >
< param name = "File" value = "Log/debug.log"/>
< param name = "Append" value = "true"/>
< param name = "MaxFileSize" value = "5000KB"/>
< param name = "Maxbackupindex" value = "2"/>
< layout class = "Org.apache.log4j.PatternLayout" >
< param name = "Conversionpattern" value =%d{hh:mm:ss. SSS}%c--%m "/>
</Layout >
< filter class = "Org.apache.log4j.varia.LevelRangeFilter" >
< param name = "Levelmin" value = "DEBUG"/>
< param name = "Levelmax" value = "DEBUG"/>
</Filter >
</Appender >

<!--config info= "info"/-->
< Appender name = "Info_log" class = "Org.apache.log4j.RollingFileAppender" >
< param name = "File" value = "Log/denet.log"/>
< param name = "Append" value = "true"/>
< param name = "MaxFileSize" value = "5000KB"/>
< param name = "Maxbackupindex" value = "2"/>
< layout class = "Org.apache.log4j.PatternLayout" >
< param name = "Conversionpattern" value = "%d{iso8601}%c--%m"/>
</Layout >
< filter class = "Org.apache.log4j.varia.LevelRangeFilter" >
< param name = "Levelmin" value = "INFO"/>
< param name = "Levelmax" value = "INFO"/>
</Filter >
</Appender >

<!--config error= "error"/-->
< Appender name = "Error_log" class = "Org.apache.log4j.RollingFileAppender" >
< param name = "File" value = "Log/error.log"/>
< param name = "Append" value = "true"/>

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.