Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2.3 rotating log file number incorrectly

Tags:

log4j2

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.

like image 343
Srilakshmi Chandolu Avatar asked Mar 07 '23 00:03

Srilakshmi Chandolu


1 Answers

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

<DefaultRolloverStrategy max="10" fileIndex="min" />
like image 132
sazzad Avatar answered Apr 25 '23 13:04

sazzad