Size-based Log Rotation
To rotate logs when a file size limit is reached:
Create an appender based on
RollingFileAppender
.Include a fixed window rolling policy.
Sample
<Configuration status="warn" name="MyApp" packages="">
<Appenders>
<RollingFile name="MyFile" fileName=" logs/app.log " filePattern=" logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.zip">
<PatternLayout>
<pattern>%d %p %C{1.} [%t] %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="1 MB"/>
</Policies>
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Root level="error">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>