-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-115809: Improve TimedRotatingFileHandler.getFilesToDelete() #115812
gh-115809: Improve TimedRotatingFileHandler.getFilesToDelete() #115812
Conversation
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.
@@ -232,19 +232,19 @@ def __init__(self, filename, when='h', interval=1, backupCount=0, | |||
if self.when == 'S': | |||
self.interval = 1 # one second | |||
self.suffix = "%Y-%m-%d_%H-%M-%S" | |||
self.extMatch = r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(\.\w+)?$" | |||
extMatch = r"(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(?!\d)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the negative lookaheads just to capture the preceding and following parts around the date-time suffix? Please add a comment about why they're used. Otherwise, looks good, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are not capturing. They are to ensure that the suffix is not preceded or followed by digits, that decreases the chance of accident wrong matches. In "12024-03-2024-03-01", it should not match "12024-03-2024-03-01", but "12024-03-2024-03-01". This code no longer requires that the datetime suffix is separated by dots from other parts, "foo2024-03-01bar.log" is now supported. Although, it is merely an optimization, because the following check filters out false matches.
I am not sure what kind of comment is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what kind of comment is needed here.
Just what you said in your comment above, nothing more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Does it look good to you?
When you're done making the requested changes, leave the comment: |
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…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 <[email protected]>
…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 <[email protected]>
GH-116261 is a backport of this pull request to the 3.12 branch. |
GH-116262 is a backport of this pull request to the 3.11 branch. |
…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 <[email protected]>
…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 <[email protected]>
…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.
…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.
…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.
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.