Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
serhiy-storchaka opened this issue Feb 22, 2024 · 0 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Feb 22, 2024

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

@serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes labels Feb 22, 2024
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Feb 22, 2024
Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
serhiy-storchaka added a commit that referenced this issue Mar 3, 2024
…5812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 3, 2024
…ythonGH-115812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
(cherry picked from commit 87faec2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 3, 2024
…ythonGH-115812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
(cherry picked from commit 87faec2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Mar 3, 2024
…GH-115812) (GH-116261)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
(cherry picked from commit 87faec2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Mar 3, 2024
…GH-115812) (GH-116262)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
(cherry picked from commit 87faec2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
…ythonGH-115812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
adorilson pushed a commit to adorilson/cpython that referenced this issue Mar 25, 2024
…ythonGH-115812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ythonGH-115812)

Improve algorithm for computing which rolled-over log files to delete
in logging.TimedRotatingFileHandler. It is now reliable for handlers
without namer and with arbitrary deterministic namer that leaves
the datetime part in the file name unmodified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
Development

No branches or pull requests

1 participant