Details
Description
We are using rolling file appender with SizeBasedTriggeringPolicy. The counter in file name is padded with 0. We observed that Log4j2 RollingFile appender does not increment the counter beyond 10 and overwrites the 10th rolled file.
Simple test case:
import org.apache.commons.lang3.RandomStringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class LogTest { private static final Logger logger = LogManager.getLogger("LogTest"); public static void main(String[] args) throws Exception { for (long i=0; ; i+=1) { logger.info("Sequence: " + i); logger.debug(RandomStringUtils.randomAscii(128, 512)); Thread.sleep(250); } } }
The log4j2.xml configuration:
<?xml version="1.0" encoding="UTF-8"?> <Configuration status="debug" verbose="true" dest="err" name="XmlProperties"> <Properties> <Property name="baseFilename">rolling_test.log</Property> <Property name="pattern">%d{HH:mm:ss.SSS} [%t] %-5level %logger{1.} - %msg%n</Property> </Properties> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> <RollingFile name="RollingFile" fileName="${baseFilename}" filePattern="${baseFilename}.%02i" immediateFlush="true" append="true"> <PatternLayout pattern="${pattern}"/> <Policies> <SizeBasedTriggeringPolicy size="1 KB"/> </Policies> <DefaultRolloverStrategy max="99"/> </RollingFile> </Appenders> <Loggers> <Logger name="LogTest" level="trace"/> <Logger name="org.apache.logging.log4j.status" level="trace"/> <Root level="info"> <AppenderRef ref="Console" level="info"/> <AppenderRef ref="RollingFile"/> </Root> </Loggers> </Configuration>
Log4j2 creates the files:
rolling_test.log rolling_test.log.01 rolling_test.log.02 rolling_test.log.03 rolling_test.log.04 rolling_test.log.05 rolling_test.log.06 rolling_test.log.07 rolling_test.log.08 rolling_test.log.09 rolling_test.log.10
When counter 10 is reached, rolling_test.log.10 file is being overwritten when rolled.
Attachments
Issue Links
- relates to
-
LOG4J2-531 Rolled log files overwritten by RollingFile appender with composite time and size based policies
- Closed