Skip to content

TimedRotatingFileHandler: reliable algorithm to determine the files to delete #115809

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

There were many issues related to removing old files in TimedRotatingFileHandler:

It is complicated because the namer attribute allows arbitrary transformation of the file name.

  1. Multiple TimedRotatingFileHandler with similar names but different backup counts do not work #93205 almost nailed the case without namer. But when there are two handlers with the same basename, and one has no namer, while other has a simple namer that adds an extension, the former handler will delete logs of the latter one. This is because the regular expression extMatch includes an optional extension. It is a remnant from former attempts to handle rotation, and is not needed now. The issue can be fixed by removing it.

  2. It is even more complicated when we have more complex namer. It can add more complex suffix, it can modify the prefix. We can only expect that it leaves the datetime part unchanged. I think that the most reliable way to find candidates for deletion is to find the datetime part in the file, then generate a new filename for this datetime and compare it with the original filename. It should work for arbitrary deterministic namer that does not modify the datetime part, and should not produce false positives.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions