[New-bugs-announce] [issue2317] TimedRotatingFileHandler logic for removing files wrong

Per Cederqvist report at bugs.python.org
Mon Mar 17 09:29:36 CET 2008


New submission from Per Cederqvist <ceder at lysator.liu.se>:

There are three issues with log file removal in the
TimedRotatingFileHandler class:

 - Removal will stop working in the year 2100, as the code assumes that
   timestamps start with ".20".

 - If you run an application with backupCount set to a high number, and
   then restarts it with a lower number, the code will still not remove
   as many log files as you expect.  It will never remove more than one
   file when it rotates the log.

 - It assumes that no other files matches baseFilename + ".20*", so
   make sure that you don't log to both "log" and
   "log.20th.century.fox" in the same directory!

Suggested fix: use os.listdir() instead of glob.glob(), filter all
file names using a proper regexp, sort the result, and use a while
loop to remove files until the result is small enough.  To reduce the
risk of accidentally removing an unrelated file, the filter regexp
should be based on the logging interval, just as the filename is.

My suggested fix means that old files may not be removed if you change
the interval.  I think that is an acceptable behavior, but it should
probably be documented to avoid future bug reports on this subject. :-)

----------
components: Library (Lib)
messages: 63626
nosy: ceder
severity: normal
status: open
title: TimedRotatingFileHandler logic for removing files wrong
type: behavior
versions: Python 2.5

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2317>
__________________________________


More information about the New-bugs-announce mailing list