是否可以滚动日志,而无需创建备份?

时间:2015-06-16 07:56:34

标签: java logging log4j

我想创建一个滚动指标日志文件,其中每隔几分钟就会将指标数据写入其中。因此,文件将变得非常快,但其中的实际相关信息只是一个小的1小时时间窗口。我不想备份它。

使用log4j,有没有办法创建滚动appender,而不是每小时创建一个备份文件?

1 个答案:

答案 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.