|
Copy a log4j or write a log4j to WEB-INF / classes
log4j content such as:
-------------------------------------------------- ----------------------------------
log4j.rootCategory = DEBUG, stdout, R
# Set the level to DEBUG if you want to log all SlideExceptions (some of them aren't errors)
log4j.category.org.apache.slide.common.SlideException = FATAL
#########################################
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
# log4j.appender.stdout.layout.ConversionPattern =% 5p [% t] (% F:% L)-% m% n
# log4j.appender.stdout.layout.ConversionPattern =% 4p [% t]% c-% m% n
log4j.appender.stdout.layout.ConversionPattern = [% t]% -5p% -20c {2}-% m% n
log4j.appender.R = org.apache.log4j.RollingFileAppender
log4j.appender.R.File = logger.log
log4j.appender.R.ImmediateFlush = true
log4j.appender.R.MaxFileSize = 100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex = 1
log4j.appender.R.layout = org.apache.log4j.PatternLayout
# log4j.appender.R.layout.ConversionPattern =% p% t% c-% m% n
# log4j.appender.R.layout.ConversionPattern =% 4p [% t]% c-% m% n
log4j.appender.R.layout.ConversionPattern =% d {ABSOLUTE} [% t]% -5p% -30c {3}% x-% m% n
Use as:
import org.apache.log4j.Logger;
Then you need to write the following sentence at the beginning of the class
private final static Logger log =
Logger.getLogger (ClassName.class); // Note that what is written here is the class name of the current class.
So you have a log object called log, this log has the following centralized usage
log.info (); // General information
log.debug (); // Debug information
log.error (); // Error message
log.warn (); // Warning information
log.fatal (); // fatal error message |
|