Application of Jakarta commons logging (jcl) -- Implement log output with log4j/jdk5 log

Source: Internet
Author: User

Jakarta commons logging (jcl)Application

--AndLog4j/jdk5 logLog output

 

Abstract: This article briefly describes how to use log4j/jdk5 log and Apache universal log package commmons-logging to output logs.

Commons-logging.properties file configuration information
# Org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. simplelog
# Must be one of ("trace", "debug", "info", "Warn", "error", or "Fatal ").
# Use log4j as the output medium
Org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. log4jcategorylog

# Jdk5 Logger
# Org. Apache. commons. Logging. log = org. Apache. commons. Logging. impl. jdk14logger

 

# Log4j. properties file configuration information. It is best to put log4j. properties in classpath.
# For example, the web-INF/classes directory or other classpath directories.
Log4j. rootlogger = error, stdout, lf5, file
Log4j. appender. stdout = org. Apache. log4j. leleappender
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
Log4j. appender. stdout. layout. conversionpattern = [start] % d {yyyy/mm/DD/HH: mm: SS} [date] % N % P [Priority] % N % x [NDC] % N % T [thread] n % C [category] % N % m [Message] % N % N

Log4j. appender. File = org. Apache. log4j. rollingfileappender
Log4j. appender. file. File = sdcrm. Log
Log4j. appender. file. maxfilesize = 100kb
Log4j. appender. file. maxbackupindex = 5
Log4j. appender. file. layout = org. Apache. log4j. patternlayout
Log4j. appender. file. layout. conversionpattern = [start] % d {yyyy/mm/DD/HH: mm: SS} [date] % N % P [Priority] % N % x [NDC] % N % T [thread] n % C [category] % N % m [Message] % N % N

Log4j. appender. lf5 = org. Apache. log4j. lf5.lf5appender
Log4j. appender. lf5_appender.maxnumberofrecords = 2000

 

Log. Java Interface Method
Private Static log lg = logfactory. getlog (this. getclass (). getname ());
Public static void debug (string classname, string debugstr ){
Log = logfactory. getlog (classname );
If (log. isdebugenabled ()){
Log. debug (debugstr );
}
}

 

Public static void Info (string classname, string infostr ){
Log = logfactory. getlog (classname );
If (log. isinfoenabled ()){
Log.info (infostr );
}
}

 

Public static void warn (string classname, string warnstr ){
Log = logfactory. getlog (classname );
If (log. iswarnenabled ()){
Log. Warn (warnstr );
}
}

 

Public static void error (string classname, string infostr ){
Log = logfactory. getlog (classname );
If (log. iserrorenabled ()){
Log. Error (infostr );
}
}

 


Public static void fatal (string classname, string infostr ){
Log = logfactory. getlog (classname );
If (log. isfatalenabled ()){
Log. Fatal (infostr );
}
}


Call method:
Logmgn. Error (this. getclass (). getname (), "error message ");

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.