[logback-dev] Deleting old RollingFileAppender log files

Greg Thomas greg.d.thomas at gmail.com
Thu May 5 14:48:55 CEST 2011


There's a ticket open - http://jira.qos.ch/browse/LBCORE-147 - that it
causing me grief. I'd like to offer to have a go at fixing it.

The problem as I see it is that if you keep, for example, 7 days worth
of log files, then ...

On day 8, the appender deletes the log file for day 1
On day 9, the appender deletes the log file for day 2
(Day 10 has no activity)
On day 11, the appender deletes the log file for day 4

So, the log file for day 3 hangs around indefinitely until it's tidied
up manually.

I can see two possible solutions for this;
a) Search back for a configurable amount of time, and delete more than
one log file. So with the above example with a 1 day search back
window,
On day 8, the appender deletes the log files for day 1 and day 0 if they exist.
On day 9, the appender deletes the log files for day 2 and day 1 if they exist.
(Day 10 has no activity)
On day 11, the appender deletes the log files for day 4 and day 3 if they exist.

b) Check the contents of the directory that the log files are stored
in, and delete all those that are older than the required time, so ...
On day 8, the appender checks the directory, and finds that the file
for day 1 has a name pattern that is over 7 days old, and deletes it.
On day 9, the appender checks the directory, and finds that the file
for day 2 has a name pattern that is over 7 days old, and deletes it.
(Day 10 has no activity)
On day 11, the appender checks the directory, and finds that the file
for days 3 and 4 have a name pattern that is over 7 days old, and
deletes them.

I think my preference is probably for option a), but I'd rather spend
the time and effort implementing something that is more likely to be
accepted as a patch. What do the maintainers think is the correct way
to fix this issue?

Thanks,

Greg


More information about the logback-dev mailing list