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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With