og4j.rootLogger=debug, stdout, R
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=%d %5p [%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 %5p [%t] (%F:%L) - %m%n
2、在入口類的靜態區初始化log4j
static {
PropertyConfigurator.configure(
YesFTPClientFrame.class.getResource("log4j.propertIEs"));
}
3、在每一個需要log的地方都初始化一個私有靜態的變量
private static Logger logger = Logger.getLogger(xx.class);
4、使用log4j提供的方法
logger.info(”hello”);
5、用log4j輸出異常的堆棧信息
logger.error("oops, got an exception: ", e);