0
votes

Log4j2 createOnDemand="true" does not allow creation of new file on a daily basis in-spite of using RollingFile Appenders with TimeBasedTriggeringPolicy.

Below is my log4j2.xml file. I have two appenders, one is for all logs, another is for a custom purpose, which needs to be generated only on demand, but the createOnDemand is overriding the Rolling nature of the log and it is not allowing to create new log file for the custom log.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <RollingFile name="App" 
                fileName="app.log" 
                filePattern="app.%d{yyyy-MM-dd}.log">
            <PatternLayout pattern="[%t] %d{yyyy-MM-dd HH:mm:ss,SSS zzz} %-5p %l - %m%n" />
            <Policies>
                <TimeBasedTriggeringPolicy interval="1" />
            </Policies>
        </RollingFile>
        <RollingFile name="custom"
                 fileName="appCustom.log"
                 filePattern="appCustom.%d{yyyy-MM-dd-HH-mm}.log"
                 createOnDemand="true">
        <PatternLayout pattern="[%t] %d{yyyy-MM-dd HH:mm:ss,SSS zzz} %-5p %l - %m%n" />
        <Policies>
            <TimeBasedTriggeringPolicy interval="1" />
        </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Logger name="AppLogger" level="info" additivity="false">
                <AppenderRef ref="App"/>
            </Logger>
        <Logger name="customLogger" level="info" additivity="false">
            <AppenderRef ref="custom"/>
        </Logger>
        <Root level="info">
                <AppenderRef ref="file" />
        </Root>
    </Loggers>
</Configuration>
1

1 Answers

0
votes

I have found the fix for the above issue. This was an existing bug in lo4j2 which is fixed in the version - 2.13.1

Below are the links :

https://issues.apache.org/jira/browse/LOG4J2-2759

https://logging.apache.org/log4j/2.x/changes-report.html#a2.13.3

I was using 2.11.0

Upgrading resolved my issue.