The normal behavior of the Log4j RollingFileAppender is to roll when the first log message occurs on a different day, but some feel warm and fuzzy with empty logfiles for each date, even if nothing occurred. Is there a way to force it to roll after midnight without writing dummy messages to the log?
The normal behavior of the Log4j RollingFileAppender is to roll when the first log
Share
I’ve looked at this code very closely – the simple answer is ‘no’. The rollover is triggered as part of the doAppend() flow on the Appender – the only way to trigger it is to log something.
You could fake this with cron: just have a cron script touch the file for tomorrow at like 11:58. That will get you the empty logfile behavior you’re looking for.
Here’s the code that implements the rollover function: