Description
In our log4j configuration we use SizeBasedTriggeringPolicy and DefaultRolloverStrategy(max>1) :
<Appenders> <RollingRandomAccessFile name="file" fileName="log/server.log" filePattern="log/server-%d{yyyy-MM-dd'T'HH-mm-ss}.log.gz"> <PatternLayout> <pattern>%level{length=1} %date{MMdd-HHmm:ss,SSS} %logger{1.} %message %X [%thread]%n </pattern> </PatternLayout> <Policies> <OnStartupTriggeringPolicy/> <SizeBasedTriggeringPolicy size="10 MB"/> </Policies> <DefaultRolloverStrategy max="2000"/> </RollingRandomAccessFile> </Appenders>
After upgrading to log4j-core 2.11.2 we have noticed that after rollover insttead of creating new files same file gets overwritten.
Looks like the issue is that
org.apache.logging.log4j.core.appender.rolling.PatternProcessor#formatFileName gives same filename for rollover, and the difference between 2.11.1 version is that field "prevFileTime" never reseted after first time*:*
2.11.2 org.apache.logging.log4j.core.appender.rolling.PatternProcessor#updateTime
public void updateTime() { if (nextFileTime != 0) { prevFileTime = nextFileTime; } }
it was always reseted in 2.11.1
2.11.1 org.apache.logging.log4j.core.appender.rolling.PatternProcessor#updateTime
public void updateTime() {
prevFileTime = nextFileTime;
}
so the same time(prevFileTime) will be always used to form the filename for rollover
org.apache.logging.log4j.core.appender.rolling.PatternProcessor#formatFileName(org.apache.logging.log4j.core.lookup.StrSubstitutor, java.lang.StringBuilder, boolean, java.lang.Object)
final long time = useCurrentTime ? currentFileTime != 0 ? currentFileTime : System.currentTimeMillis() : prevFileTime != 0 ? prevFileTime : System.currentTimeMillis();