Log4j: rotate the log file even if the file has not changed

I try to rotate the log file every day using DailyRollingFileAppender, but I have a problem: the log files are not updated every day, so it does not rotate when there are no new things in it.

Is there a way in log4j.properties that I can set it so that log4j changes the log file every day, even if the file has no changes?

+3
source share
1 answer

Log4j DailyRollingFileAppenderwill not output an empty file if there was no log. From 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) {
+6
source

Source: https://habr.com/ru/post/1727702/


All Articles