The brain is not good, so some should still be recorded.
1. Build a log4j.properties configuration file, put it under the same path to the portable entry class.
Og4j.rootlogger = Debug, Stdout, R
Log4j.appender.stdout = org.apache.log4j.consoleappenderlog4j.Appender.stdout.Layout = org.apache.log4j.patternlayout
# Pattern to output the caller's file name and line number.log4j.connder.stdout.Layout.conversionPattern =% D% 5P [% T] (% F:% L) -% M% N
Log4j.Appender.r = org.apache.log4j.rollingfileappenderlog4j.Appender.r.file = yesftp.log
Log4j.appender.r.maxfilesize = 1000kb # Keep One Backup filelog4j.Appender.r.maxbackupindex = 1
Log4j.rapnder.r.Layout = org.apache.log4j.patternLayoutLog4j.Appender.r.Layout.conversionPattern =% D% 5P [% T] (% F:% L) -% M% N
2. Initialize log4j in static zone in the entrance class
Static {propertyconfigurator.configure (YESFTPCLIENTFRAME.CLASS.GETRESOURCE ("log4j.properties");}
3, a private static variable is initialized in each place where logs needed
Private static logger logger = logger.getlogger (xx.class);
4, the method of using log4j
Logger.info ("Hello");
5, using log4j output exception stack information
Logger.Error ("OOPS, GOT An Exception:", E);