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
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.
Thank you Remko.Your suggestion works! Sorry I posted the wrong link. I was using the same section as you pointed out in your post.
I added the above two lines to the example in the manual page. The site will be updated with the next release (2.5). Thanks for pointing this out.
If the above resolved the problem can you close this question? Thanks!
I've checked your answer, Remko. I hope that closes the question. Thank you once again for helping out.
Will this still work even if %i is not used in the file naming pattern?