是否可以使用logging.jl配置使用log4j旋转和压缩文件?
目前看来有两个策略 - TimeBased(压缩文件,但不是基于大小)和SizeBased(不压缩文件),但我看不到选项如何同时配置旋转和压缩。例如,"旋转大于10M的文件并压缩它们"。
如果有人有logging.yml的例子,我会非常感激。
目前这是logging.yml但它不会根据大小旋转而且不会压缩:
rootLogger: DEBUG, console, file
log4j.appender: org.apache.log4j.rolling.RollingFileAppender
file:
type: org.apache.log4j.rolling.RollingFileAppender
file: ${path.logs}/${cluster.name}.log
rollingPolicy: org.apache.log4j.rolling.TimeBasedRollingPolicy
rollingPolicy.FileNamePattern: ${path.logs}/${cluster.name}.log.%d{yyyy-MM-dd}.gz
trigeringPolicy: org.apache.log4j.SizeBasedTriggeringPolicy
trigeringPolicy.MaxFileSize: 10M
trigeringPolicy.MaxBackupIndex: 5
layout:
type: pattern
conversionPattern: "%d{ISO8601}[%-5p][%-25c] %m%n"
提前致谢!
答案 0 :(得分:2)
这对我有用。 使用2.17版本。
log4j.rootLogger = INFO,loggerId log4j.appender.loggerId = org.apache.log4j.rolling.RollingFileAppender log4j.appender.loggerId.rollingPolicy.maxIndex = 5 log4j.appender.loggerId.triggeringPolicy = org.apache.log4j.rolling.SizeBasedTriggeringPolicy log4j.appender.loggerId.triggeringPolicy.MaxFileSize =千万 log4j.appender.loggerId.rollingPolicy.FileNamePattern =工人─%i.log.gz log4j.appender.loggerId.rollingPolicy.ActiveFileName = worker.log log4j.appender.loggerId.layout = org.apache.log4j.PatternLayout log4j.appender.loggerId.layout.ConversionPattern =%d [%t]%-5p(%F:%L) - %m%n