Logback - cleanHistoryOnStart does not work

Avi*_*Avi 5 logging logback

I have an application that runs on several servers which have been running for a few months with a java application that uses logback. Turns out we forgot to limit the history size.

I configured the following params:

 - maxHistory: 10
 - cleanHistoryOnStart: true
Run Code Online (Sandbox Code Playgroud)

I redeployed the app but when it started, the files remained and haven't been deleted.

Shouldn't this configuration make sure that the files are deleted upon startup? What would be the way to do it?

小智 2

这是一个老问题,但如果其他人遇到这个问题,以下是可能发生这种情况的一些可能原因:

  • 该maxHistory值意味着意想不到的东西。来自Logback 文档:

    例如,如果您指定每月滚动,并将 maxHistory 设置为 6,则将保留 6 个月的存档文件,并删除超过 6 个月的文件。

  • 所选的附加程序不支持该参数。
  • 拼写错误,例如清除HistoryOnStart。
  • 旧版本的Logback;cleanHistoryOnStart1.0.1中引入

在最后 3 种情况下,应在某处记录错误,内容如下:

日志文件错误:[cleanHistoryOnStart] 没有适用的操作,当前模式是 [...]

如果您不确定检查的位置是否正确,请故意拼写错误并查找日志。然后更正拼写错误并检查错误是否仍然存在(这次是因为它无效)。