Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to define the date/time pattern for TimeBasedTriggeringPolicy in Log4j2

I am new in Log4j2 and want to use the RollingFileAppender. Further as rollover I want to use the TimeBaseTriggeringPolicy:

The TimeBasedTriggeringPolicy causes a rollover once the date/time pattern no longer applies to the active file.

On the site above there is an example for such an TimeBasedTriggeringPolicy:

<?xml version="1.0" encoding="UTF-8"?>    
<Configuration status="warn" name="MyApp" packages="">
    <Appenders>
        <RollingFile name="RollingFile" fileName="logs/app.log"
    filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy />
                <SizeBasedTriggeringPolicy size="250 MB"/>
            </Policies>
        </RollingFile>
    </Appenders>
    <Loggers>
        <Root level="error">
            <AppenderRef ref="RollingFile"/>
        </Root>
    </Loggers>
</Configuration>

Where is in the configuration above the "date/time pattern" defined, that determines if the active file applies to it or not?

Thanks for your help!

like image 966
mrbela Avatar asked Jan 30 '15 11:01

mrbela


1 Answers

That is the filePattern. In your config:

filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">

The most granular time unit in the above is dd (days) so it will rollover daily at midnight.

like image 87
Remko Popma Avatar answered Nov 15 '22 08:11

Remko Popma