Logback RollingFileAppender 是否重命名或截断现有文件

Does Logback RollingFileAppender rename or truncate existing file

logback rename existing log files with a numerical suffix, then re-create the original empty log file 还是 truncate the original log file in place after creating a copy

我正在尝试将 AWS Cloudwatch Agent 与使用 logback 的 Java 应用程序结合使用。我们目前使用 RollingFileAppenderFixedWindowRollingPolicySizedBasedTriggeringPolicy

A RollingFileAppenderFileAppender 可以滚动日志文件;这个附加程序可以记录到一个名为 myLog.log 的文件,当满足给定条件时,将其目标更改为另一个文件。它有两个必需的子组件:

  • 执行翻转的RollingPolicy
  • A TriggeringPolicy 确定是否以及何时发生翻转

这就是背景,现在,关于你的问题......你写道你正在使用 FixedWindowRollingPolicy 所以当发生翻转时,Logback 会将 currentLogFle 重命名为 currentLogFle1 然后创建一个新的 currentLogFle 然后它成为活动输出目标。所以这个问题的答案...

Does logback rename existing log files with a numerical suffix, then re-create the original empty log file or truncate the original log file in place after creating a copy?

... 是:

Logback will rename existing log files with a numerical suffix, then re-create the original empty log file.

有一个有用的 table in the docs 描述了这种行为。