我正在使用 log4j2 的滚动文件附加程序和 log4j2.properties 配置。日志文件在日志文件中每几行日志的位置被翻转,以及在生成新的压缩文件后日志文件本身被重写的位置。
这是我的配置文件,
status = info
dest = err
name = PropertiesConfig
#file location
property.filename = C:/DataCollector/test.log
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = info
#console
appender.console.type = Console
appender.console.name = LogToConsole
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = info
appender.rolling.type = RollingFile
appender.rolling.name = LogToRollingFile
appender.rolling.fileName = ${filename}
appender.rolling.filePattern = test1-%d{MM-dd-yy-HH-mm-ss}-%i.log.gz
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
#1 day
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20
appender.rolling.append=false
logger.app.name = xxx.datacollector
logger.app.level = info
logger.app.additivity = false
logger.app.appenderRef.rolling.ref = LogToRollingFile
logger.app.appenderRef.console.ref = LogToConsole
rootLogger.level = info
rootLogger.appenderRef.stdout.ref = LogToConsole
我必须每天翻转,而且翻转策略的大小限制也可能是 10mb。
我也尝试添加“append”和“immediateFlush”,但输出没有变化。
输出文件示例: