Issue 2317: TimedRotatingFileHandler logic for removing files wrong (original) (raw)

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

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. :-)