Log4j2的RollingFileAppender详解

[Q&A] RollingFileAppender 什么功能?

当满足条件(日志大小、指定时间等)重命名打包原日志文件进行归档,生成新日志文件用于日志写入。

参数TypeDescription
nameStringThe name of the Appender.
fileNameStringThe name of the file to write to. If the file, or any of its parent directories, do not exist, they will be created.
filePatternStringThe pattern of the file name of the archived log file.
createOnDemandboolean当该属性设置为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>
  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值