1.配置文件如下:
log4j.rootCategory=WARN, dest1,A1
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%-5p: %m%n
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=log/sms.log
log4j.appender.A1.DatePattern='sms'yyyyMMdd-HH-mm'.log'
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=[%d] %t %c %-5p - %m%n
现在把该注意的几点写出来:
1.log4j.appender.R=org.apache.log4j.DailyRollingFileAppender,不要还用org.apache.log4j.RollingFileAppender
2.DailyRollingFileAppender没有MaxFileSize,MaxBackupIndex属性,所以必须注解
3. 如buzhiming99(不知名) 所说:用PropertyConfigurator就不需要用BasicConfigurator