You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Petras (Jira)" <ji...@apache.org> on 2020/02/17 18:00:06 UTC

[jira] [Created] (LOG4J2-2784) Rolling stuck at counter 10 by RollingFile appender when counter is zero padded

Petras created LOG4J2-2784:
------------------------------

             Summary: Rolling stuck at counter 10 by RollingFile appender when counter is zero padded
                 Key: LOG4J2-2784
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2784
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 2.13.0, 2.12.1
         Environment: Windows 10 Pro x64 v1809
Oracle Java 11.0.3
            Reporter: Petras


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:
{code:java}
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);
        }
    }
}
{code}

The log4j2.xml configuration:
{code:xml}
<?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>
{code}

Log4j2 creates the files:
{code}
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
{code}
When counter 10 is reached, {{rolling_test.log.10}} file is being overwritten when rolled.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)