简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM