It is hard to remember, so some of the Notes should be recorded.
1. Create a log4j. properties configuration file and place it in the same path of the main portal class.
Og4j. rootlogger = debug, stdout, R
Log4j. appender. stdout = org. Apache. log4j. leleappender
Log4j. appender. stdout. layout = org. Apache. log4j. patternlayout
# Pattern to output the caller's file name and line number.
Log4j. appender. stdout. layout. conversionpattern = % d % 5 p [% T] (% F: % L)-% m % N
Log4j. appender. r = org. Apache. log4j. rollingfileappender
Log4j. appender. R. File = yesftp. Log
Log4j. appender. R. maxfilesize = 1000kb
# Keep one backup file
Log4j. appender. R. maxbackupindex = 1
Log4j. appender. R. layout = org. Apache. log4j. patternlayout
Log4j. appender. R. layout. conversionpattern = % d % 5 p [% T] (% F: % L)-% m % N
2. initialize log4j in the static area of the entry class
Static {
Propertyconfigurator. Configure (
Yesftpclientframe. Class. getresource ("log4j. properties "));
}
3. initialize a private static variable in every location where logs are needed.
Private Static logger = logger. getlogger (XX. Class );
4. Use the methods provided by log4j
Logger.info ("hello ");
5. Use log4j to output abnormal stack information
Logger. Error ("Oops, got an exception:", e );