log4j2 - limiting the number of log files
I never used log4j2 so far but the documentation of the RollingFileAppender gives you a lot of configuration examples.
Interesting for you seams to be something like this (using DefaultRolloverStrategy
):
<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> <SizeBasedTriggeringPolicy size="5 MB"/> </Policies> <DefaultRolloverStrategy max="20"/></RollingFile>