log4j2-保留日志文件的最后7天 [英] log4j2 - keep last 7days of log file

查看:184
本文介绍了log4j2-保留日志文件的最后7天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要保留最近3天的日志文件,每个文件大小不超过10MB,如何在log4j2.yml文件中配置?

To keep the last 3days of log file with each file size up to 10MB, how to configure in log4j2.yml file?

我试过了,

filePattern: ${log}/${app}-archive/${app}-%d{MM-dd-yyyy}-%i.log"
...
Policies:
  TimeBasedTriggeringPolicy:
   interval: 1
   modulate: true
  SizeBasedTriggeringPolicy:
   size: 10 MB
 DefaultRolloverStrategy:
   delete:
    basePath: "${log}/${app}-archive"
    maxDepth: 1
    IfFileName:
     glob: "*.log"
    IfLastModified:
     age: 3d

,即使当天是今天的日志,它最多只能在同一天创建7个归档文件并删除旧文件.如果lastModified<是否有办法保存尽可能多的文件.3d?例如app-04-09-2021-8.log,app-04-09-2021-9.log,.... app-04-09-2021-39.log等.

and it creates only up to 7 archives on the same day and delete old files even though it was today's log. Is there a way to keep as much as files if its lastModified < 3d? like app-04-09-2021-8.log, app-04-09-2021-9.log,....app-04-09-2021-39.log and so on.

请指导我.

推荐答案

默认情况下, DefaultRolloverStrategy 最多保留 max 配置属性的值, 7默认情况下,根据您的用例,每天一次,基于时间的过渡间隔,如文件模式中所示, $ {app}-%d {MM-dd-yyyy}-%i.log - max 属性仅适用于%i 计数器.

By default DefaultRolloverStrategy will keep at most the value of the max configuration attribute, 7 by default, per time based rollover interval, daily in your use case as indicated in your file pattern, ${app}-%d{MM-dd-yyyy}-%i.log - the max attribute only applies only to the %i counter.

为该属性提供更大的值,您认为适当的值取决于您的日志模式.例如:

Provide a bigger value for that attribute, the value you consider appropriate depending on your log patterns. For example:

DefaultRollOverStrategy:
  max: 100
  delete:
    basePath: "${log}/${app}-archive"
    maxDepth: 1
    IfFileName:
     glob: "*.log"
    IfLastModified:
     age: 3d

请参阅相关的文档.

这篇关于log4j2-保留日志文件的最后7天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆