1、按天记录日志,日志保留7天
<RollingFile name="rollingFile" fileName="log/mylog.log" filePattern="log/$${date:yyyy-MM}/main-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true" interval="1"/>
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="log" maxDepth="2">
<IfFileName glob="*/*.log.gz" />
<IfLastModified age="7d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
2、按小时记录日志,日志保留6天
<RollingFile name="rollingFile" fileName="log/mylog.log" filePattern="log/$${date:yyyy-MM}/main-%d{yyyy-MM-dd-HH}.log.gz">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy modulate="true" interval="1"/>
</Policies>
<DefaultRolloverStrategy>
<Delete basePath="log" maxDepth="2">
<IfFileName glob="*/*.log.gz" />
<IfLastModified age="6d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
3、按大小记录日志,满20MB记录一个日志,日志保留7天;由filePattern中的%i和DefaultRolloverStrategy中max的值决定
<RollingFile name="rollingFile" fileName="log/mylog.log" filePattern="log/$${date:yyyy-MM}/main-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout pattern="[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="20 MB" />
</Policies>
<DefaultRolloverStrategy max="10">
<Delete basePath="log" maxDepth="2">
<IfFileName glob="*/*.log.gz" />
<IfLastModified age="7d" />
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
4、RollingFile 配置中默认配置append=“true”
如果为true-默认值,记录将附加到文件末尾。设置为false时,将在写入新记录之前清除文件,保留当天数据
相关文档:solr文档