我无法理解我在这里缺少的东西。下面是我的log4j.properties
# Root logger option
log4j.rootLogger=INFO, 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/broker.log
log4j.appender.file.rollingPolicy.FileNamePattern=${catalina.home}/logs/broker-.%d{yyyyMMdd-HH}.log.gz
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
答案 0 :(得分:0)
你忘记设置MaxFileSize
,只需将以下内容添加到RollingFileAppender配置中,文件名以.gz结尾即可自动压缩日志文件:
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/broker.log
log4j.appender.file.rollingPolicy.FileNamePattern=${catalina.home}/logs/broker-.%d{yyyyMMdd-HH}.log.gz
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.MaxFileSize=10M
log4j.appender.file.MaxBackupIndex=3
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
希望有所帮助