Using the TimedRotatingFileHandler along with "when='midnight'" and interval > 1, midnight is handled equally to "days" which is a little misleading.
Expectation:
setting when to 'midnight', the file is rotated every midnight (interval value should be ignored)
Current behavior:
If 'midnight' is given alongside with an interval greater than 1 (.e.g 5), the (internal) interval (24*60*60) is calculated with the given interval -> 24*60*60 * 5.
In my case, this led to some unforeseeable and unexpected behavior.
I see now that the problem is that computeRollover() returns the next nearest "midnight" time, ignoring the interval parameter, while doRollover() computes the file name by stepping back interval days. And there is the same issue with the weekly rotation.
My fix #116191 perhaps affected this issue and made it worse (if you do not consider it better). Previously, in doRollover(), if computeRollover() returned the current time, self.interval was added, so the next rollover time was set after interval days or weeks. But this behavior depended on atTime and the time of running the script.
Perhaps the safest way is to implement the correct support of the interval parameter for "midnight" and weekly rotation.
Activity
mschiess commented on Jan 14, 2022
Using the TimedRotatingFileHandler along with "when='midnight'" and interval > 1, midnight is handled equally to "days" which is a little misleading.
Expectation:
setting when to 'midnight', the file is rotated every midnight (interval value should be ignored)
Current behavior:
If 'midnight' is given alongside with an interval greater than 1 (.e.g 5), the (internal) interval (24*60*60) is calculated with the given interval -> 24*60*60 * 5.
In my case, this led to some unforeseeable and unexpected behavior.
21 remaining items
serhiy-storchaka commented on Mar 1, 2024
I see now that the problem is that computeRollover() returns the next nearest "midnight" time, ignoring the interval parameter, while doRollover() computes the file name by stepping back interval days. And there is the same issue with the weekly rotation.
My fix #116191 perhaps affected this issue and made it worse (if you do not consider it better). Previously, in doRollover(), if computeRollover() returned the current time, self.interval was added, so the next rollover time was set after interval days or weeks. But this behavior depended on atTime and the time of running the script.
Perhaps the safest way is to implement the correct support of the interval parameter for "midnight" and weekly rotation.
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
gh-90535: Fix support of interval>1 in logging.TimedRotatingFileHandl…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
[3.12] gh-90535: Fix support of interval>1 in logging.TimedRotatingFi…
[3.11] gh-90535: Fix support of interval>1 in logging.TimedRotatingFi…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…
pythongh-90535: Fix support of interval>1 in logging.TimedRotatingFil…