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 ");