Log4j RollingFileAppender has odd behavior when using the Log4j 1.x bridge
This is a bug and you should report it. The RollingFileAppenderBuilder
(cf. source code) has a filePattern
containing a date instead of a number:
String filePattern = fileName +"%d{yyy-MM-dd}";
TriggeringPolicy timePolicy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
SizeBasedTriggeringPolicy sizePolicy = SizeBasedTriggeringPolicy.createPolicy(maxSize);
CompositeTriggeringPolicy policy = CompositeTriggeringPolicy.createPolicy(sizePolicy, timePolicy);
RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
.setConfig(config)
.setMax(maxBackups)
.build();
return new AppenderWrapper(RollingFileAppender.newBuilder()
.setName(name)
.setConfiguration(config)
.setLayout(fileLayout)
.setFilter(fileFilter)
.setBufferedIo(bufferedIo)
.setImmediateFlush(immediateFlush)
.setFileName(fileName)
.setFilePattern(filePattern)
.setPolicy(policy)
.setStrategy(strategy)
.build());
and hence it behaves more like the DailyRollingFileAppender
, then a Log4j 1.x RollingFileAppender
.
As a workaround you can use the older Log4j1ConfigurationFactory
by setting these system properties:
log4j2.configurationFactory=org.apache.log4j.config.Log4j1ConfigurationFactory
log4j2.configurationFile=classpath:log4j.properties