Warm tip: This article is reproduced from serverfault.com, please click

Setting rollover strategy in log4j2.properties

发布于 2015-11-09 14:31:57

Can anybody help me with setting the rolloverstrategy in log4j2.properties ? I have set it up as -

#Appender
appender.test.type=RollingFile
appender.test.name=test
appender.test.fileName=${logPath}/test.log
appender.test.filePattern = ${logPath}/test-%i.log
appender.test.layout.type=PatternLayout
appender.test.layout.pattern=%d{ISO8601} %-5p [%t] %m%n
appender.test.policies.type=Policies
appender.test.policies.size.type=SizeBasedTriggeringPolicy
appender.test.policies.size.size=1MB
appender.test.strategies.type=Strategies
appender.test.strategies.rollover.type=DefaultRolloverStrategy
appender.test.strategies.rollover.max=5

I wrote this consulting https://logging.apache.org/log4j/2.x/manual/configuration.html#ConfigurationSyntax

I didn't find anything for implementing rollover strategy and what you see above is what I thought would work.But unfortunately and obviously it does not.

Here is the error:

2015-11-09 13:30:42,175 localhost-startStop-1 ERROR Unable to locate plugin for Strategies
Questioner
flume
Viewed
0
Remko Popma 2015-11-10 07:47:44

There is another section on that page that may be useful:

http://logging.apache.org/log4j/2.x/manual/configuration.html#Properties

It contains an example properties configuration with rollover. Furthermore you can find the supported RollingFileAppender Parameters on its manual page: http://logging.apache.org/log4j/2.x/manual/appenders.html#RollingFileAppender

Try this:

appender.test.strategy.type=DefaultRolloverStrategy
appender.test.strategy.max=5

Let me know if it works and I'll add it to the manual page.