我想创建一个滚动指标日志文件,其中每隔几分钟就会将指标数据写入其中。因此,文件将变得非常快,但其中的实际相关信息只是一个小的1小时时间窗口。我不想备份它。
使用log4j,有没有办法创建滚动appender,而不是每小时创建一个备份文件?
答案 0 :(得分:0)
从文档here,您可以设置MaxBackupIndex等于零
log4j.appender.R.MaxBackupIndex=0
rollOver
public void rollOver()
Implements the usual roll over behaviour.
If MaxBackupIndex is positive, then files {File.1, ..., File.MaxBackupIndex -1} are renamed to {File.2, ..., File.MaxBackupIndex}. Moreover, File is renamed File.1 and closed. A new File is created to receive further log output.
If MaxBackupIndex is equal to zero, then the File is truncated with no backup files created.