Log4j 学习笔记之三
引言:
#print to consolelog4j.rootLogger = debug, stdoutlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%5p [%t](%r %x %c) (%F:%L) - %m%nlog4j.logger.A=debug,Rlog4j.logger.B=debug,R#print to file a.loglog4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=a.log# Control the maximum log file sizelog4j.appender.R.MaxFileSize=100KB# Archive log files (one backup file here)log4j.appender.R.MaxBackupIndex=1log4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm:ss}:%p %t %c - %m%n log4j.logger.bbb.C=debug,R2log4j.logger.bbb.D=debug,R2#print to file a.loglog4j.appender.R2=org.apache.log4j.RollingFileAppenderlog4j.appender.R2.File=b.log# Control the maximum log file sizelog4j.appender.R2.MaxFileSize=100KB# Archive log files (one backup file here)log4j.appender.R2.MaxBackupIndex=1log4j.appender.R2.layout=org.apache.log4j.PatternLayoutlog4j.appender.R2.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm:ss}:%p %t %c - %m%n
运行,测试成功。
这里面我用的是maven工程,里面的log4.properties是放在classpath的,所以会自动加载,输出的a.log、b.log也是用的相对地址,所以执行后也在项目文件夹里面。 1 楼 yuyujulin 2011-07-13 感谢楼主,三篇关于log4j的都很不错,学习了