【问题标题】:PeriodicSizeRotatingFileHandler in JBoss EAP 7.3 is not deleting old logsJBoss EAP 7.3 中的 PeriodicSizeRotatingFileHandler 不删除旧日志
【发布时间】:2022-11-18 06:39:36
【问题描述】:
我在用着定期大小旋转文件处理程序根据此配置仅保留最新的日志文件;
<periodic-size-rotating-file-handler name="FILE" autoflush="true">
<formatter>
<named-formatter name="PATTERN"/>
</formatter>
<file relative-to="jboss.server.log.dir" path="server.log"/>
<rotate-size value="10k"/>
<max-backup-index value="5"/>
<suffix value=".yyyy-MM-dd"/>
<append value="true"/>
</periodic-size-rotating-file-handler>
我期望它会在当前日志文件超过“10KB”时创建一个新日志文件,并在文件总数超过“5”时删除旧日志文件。当我在同一天测试它时,这确实有效;
但是,当我有前几天的日志文件时,我希望这些规则仍然适用,但这不起作用;
从上图可以看出,它并没有删除前几天的日志文件,只是将规则应用于当天的日志文件。
我该如何解决这个问题?
【问题讨论】:
标签:
logging
jboss
jboss-eap-7
【解决方案1】:
periodic-size-rotating-file-handler 不会删除按日期旋转的文件。来自 read-resource-description 操作的 sn-p:
"result" => [{
"address" => [
("subsystem" => "logging"),
("periodic-size-rotating-file-handler" => "*")
],
"outcome" => "success",
"result" => {
"description" => "Defines a handler which writes to a file, rotating the log after a time
period derived from the given suffix string or after the size of the file grows beyond a
certain point and keeping a fixed number of backups. The suffix should be in a format
understood by the java.text.SimpleDateFormat. Any backups rotated by the suffix will not be purged during a size rotation.",
"capabilities" => [{
"name" => "org.wildfly.logging.handler",
"dynamic" => true,
"dynamic-elements" => ["periodic-size-rotating-file-handler"]
}],
描述的最后一部分谈到了这一点:
在大小轮换期间,不会清除后缀轮换的任何备份。
有一个长期存在的issue,我真的应该在某个时候抽出时间来处理。不幸的是,目前只有 cron 作业之类的东西是唯一的方法。