[Q&A] RollingFileAppender 什么功能?
当满足条件(日志大小、指定时间等)重命名
或打包
原日志文件进行归档,生成新日志文件用于日志写入。
参数 | Type | Description |
---|---|---|
name | String | The name of the Appender. |
fileName | String | The name of the file to write to . If the file, or any of its parent directories, do not exist, they will be created. |
filePattern | String | The pattern of the file name of the archived log file . |
createOnDemand | boolean | 当该属性设置为true 时,Log4j将根据需要(即首次有日志事件需要写入时)创建指定的日志文件,而不是在应用程序启动时立即创建。Defaults to false. |
<appenders>
<RollingFile name="API_JSON"
fileName="${LOG_HOME}/${FILE_NAME}.log"
filePattern="${LOG_HOME}/${FILE_NAME}_%d{yyyy-MM-dd}_%i.log.gz"
createOnDemand="true">
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<SizeBasedTriggeringPolicy size="100K"/>
</Policies>
<DefaultRolloverStrategy fileIndex="nomax">
<Delete basePath="${LOG_HOME}" maxDepth="2">
<IfFileName glob="*.log.gz">
<IfAny>
<IfAccumulatedFileSize exceeds="100M"/>
<IfAccumulatedFileCount exceeds="100"/>
<IfLastModified age="30d"/>
</IfAny>
</IfFileName>
</Delete>
</DefaultRolloverStrategy>
</RollingFile>
</appenders>