Srilakshmi Chandolu
Srilakshmi Chandolu

Reputation: 129

Log4j2.3 rotating log file number incorrectly

We are using Log4j2.3 version for logging and using xml configuration. Here it is like -

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <Appenders>
        <RollingFile name="testingAppender" fileName="Test.log"
            filePattern="logs/Test.log.%i">
            <PatternLayout>
                <pattern>[%-5p] %d{dd MMM yyyy HH:mm:ss} - %m %n</pattern>
            </PatternLayout>
            <Policies>
                <SizeBasedTriggeringPolicy size="5 MB" />
            </Policies>
            <DefaultRolloverStrategy max="10" />
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="testingLogger" level="debug">
            <AppenderRef  ref="testingAppender" level="debug" />
        </Logger>
    </Loggers>
</Configuration> 

Log files are rotating fine. But the LATEST log file is having highest rolling number Example - Test.log7, where it should be Test.log0. Log file numbers are rotating in reverse order.

Need help in this.

Upvotes: 5

Views: 2747

Answers (1)

sazzad
sazzad

Reputation: 6267

This is not incorrect but the default behavior. To get your intended behavior, try setting fileIndex attribute min.

<DefaultRolloverStrategy max="10" fileIndex="min" />

Upvotes: 8

Related Questions