Log4j无法正常工作

时间:2015-08-14 07:49:48

标签: java tomcat log4j

以下是log4j.properties文件

# Root logger option
log4j.rootLogger=DEBUG, file


    # Redirect log messages to a log file
    log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
    log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy  
    log4j.appender.file.rollingPolicy.ActiveFileName=${catalina.home}/logs/app.log  
    log4j.appender.file.rollingPolicy.FileNamePattern=${catalina.home}/logs/app-.%d{yyyyMMdd-HH}.log.gz  
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.MaxFileSize=10MB
    log4j.appender.file.MaxBackupIndex=10
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%

文件正在压缩但不是10MB。压缩后,文件大小为14MB ......有些东西似乎很奇怪

1 个答案:

答案 0 :(得分:0)

appender有一些变化,你能测试吗

log4j.appender.file=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.file.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy  
log4j.appender.file.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy 
log4j.appender.file.rollingPolicy.ActiveFileName=${catalina.home}/logs/app.log  
log4j.appender.file.rollingPolicy.FileNamePattern=${catalina.home}/logs/app-.%d{yyyyMMdd-HH}.log.gz  
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.triggeringPolicy.MaxFileSize=10MB  
log4j.appender.file.rollingPolicy.maxIndex=10
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%