Reputation: 686
We have a custom rolling policy that is declared in log4j like this:
log4j.appender.testing.rollingPolicy=com.custom.appender.TimeBasedRollingPolicy log4j.appender.testing.rollingPolicy.timeToRolloverInSeconds=60 log4j.appender.testing.rollingPolicy.FileNamePattern=/tmp/cdr.log
How can this be declared in log4j2.xml
?
Upvotes: 1
Views: 1989
Reputation: 36844
Log4j2 has a built-in time based rollover policy that may do what you want. The below configuration results in a rollover every minute:
<Appenders>
<RollingFile name="RollingFile" fileName="logs/app.log"
filePattern="logs/old/app-%d{yyyyMMdd-HHmm}-log.gz">
<PatternLayout>
<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
If you want to create a custom rollover policy, you would need to create a log4j2 plugin that implements TriggeringPolicy. A good starting point would be to look at the source code for the built-in TimeBasedTriggeringPolicy. General information on Log4j custom plugins is here.
Upvotes: 2