This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: TimedRotatingFileHandler "midnight" misleading when interval > 1
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: mschiess, python-dev, vinay.sajip
Priority: normal Keywords: patch

Created on 2022-01-14 13:50 by mschiess, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 30599 closed python-dev, 2022-01-14 13:53
Messages (5)
msg410558 - (view) Author: Mike Schiessl (mschiess) * Date: 2022-01-14 13:50
Using the TimedRotatingFileHandler along with "when='midnight'" and interval > 1, midnight is handled equally to "days" which is a little misleading.

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.
msg410565 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2022-01-14 14:52
Making a change without considering backward compatibility is premature. I've closed the PR as there appears to be something wrong with it - it references hundreds of changed files. Did you look at the 'atTime' keyword parameter of TimedRotatingFileHandler?
msg410567 - (view) Author: Mike Schiessl (mschiess) * Date: 2022-01-14 15:11
i've just checked PR and you're right, something with the PR went wrong.

Anyway, midnight (at least from the wording) specifies the "atTime". (which should be midnight). 

Again, if there's (by mistake) an interval bigger than 1 set(which in my mind makes no sense along to be used with midnight) things are getting pretty intransparent. The midnight handler created a logfile dated with 2021-12-15 (last night). Took me some time to get this sorted. (I've discovered, that I've set 30 in a default value file).

Agreed on the backward compatibility, but I would assume someone using "midnight" would not expect any other behavior than "daily at midnight" besides using the atTime to modify the rollover time. (my opinion)
msg410571 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2022-01-14 16:14
Unfortunately, you can't rely on people always doing "the sensible thing", for any number of good reasons. If a particular set of parameter values didn't cause failure, it is probably used somewhere.

Anyway, your problem goes away if interval == 1, right? If we were to tighten things up (e.g. disallowing interval > 1 with "midnight"), then it would have to be done on a deprecation cycle at the very least, ISTM.
msg410583 - (view) Author: Mike Schiessl (mschiess) * Date: 2022-01-14 18:25
Yes, enforcing interval == 1 or interval == None (which pulls the TimedRotatingFileHandler class __init__ default value which is also 1) works perfectly with midnight.

I do not see any urge on that topic - as I personally now know the issue :D - but I really feel this fix could save someones else's time someday ;) 

So going the "safe" way via deprecation cycle seems to be the right approach
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90535
2022-01-14 18:25:21mschiesssetmessages: + msg410583
2022-01-14 18:19:40iritkatrielsettype: behavior -> enhancement
versions: - Python 3.7, Python 3.8, Python 3.9, Python 3.10
2022-01-14 16:14:14vinay.sajipsetmessages: + msg410571
2022-01-14 15:11:40mschiesssetmessages: + msg410567
2022-01-14 14:52:15vinay.sajipsetmessages: + msg410565
2022-01-14 13:53:16python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request28797
stage: patch review
2022-01-14 13:50:48mschiesscreate