Log4j:即使文件没有更改,也会轮换日志文件

发布于 2024-08-16 19:50:54 字数 151 浏览 0 评论 0原文

我尝试使用 DailyRollingFileAppender 每天轮换日志文件,但我有一个问题:日志文件不会每天更新,因此当其中没有新内容时它不会轮换。

log4j.properties 中有没有一种方法可以设置它,以便 log4j 每天轮换日志文件,即使文件没有更改?

i am trying to rotate the log file everyday by using the DailyRollingFileAppender, but i have a problem: the log files are not updated everyday, so it doesn't get rotate when there is no new stuff in it.

is there a way in the log4j.properties that i can set it so that log4j rotate the log file everyday even if the file has no changes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2024-08-23 19:50:54

如果没有发生日志记录,Log4j DailyRollingFileAppender 将不会输出空文件。来自 实施

/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {

Log4j DailyRollingFileAppender will not output an empty file if no logging has occurred. From the implementation:

/**
* This method differentiates DailyRollingFileAppender from its
* super class.
*
* <p>Before actually logging, this method will check whether it is
* time to do a rollover. If it is, it will schedule the next
* rollover time and then rollover.
* */
protected void subAppend(LoggingEvent event) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文