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.

Author martonivan
Recipients markhallett, martonivan, vinay.sajip
Date 2021-08-10.09:00:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628586011.3.0.535246252938.issue40469@roundup.psfhosted.org>
In-reply-to
Content
The assumed behaviour of TimedRotatingFileHandler is to rotate log files older than configured. Even when the script is executed multiple times.

self.rolloverAt (the variable that defines when the rollover should be performed) is set after each rollover and right after initializing the file handler instance.

If the instance is initialized once (like in your script) and a rollover is performed without having the object destroyed, the logger works fine, the rollover is done and the next round is scheduled properly.

The case is not so lucky if the script runs multiple time or the logger itself is initialized multiple times during one execution. In this case, since the MTIME is read each time when the TimedRotatingFileHandler's init is called, and the file is modified (by having a new line added to the end of the file). The next execution will read the new MTIME and will never perform any rollover.

I've slightly modified your example script to demonstrate these use-cases.

Example 1: Log a single line with the script, but execute it multiple times with delays between the execution!
In bash: for i in {1..101}; do python log_40469_single.py $i; sleep 30; done

Example 2: Log multiple lines, but reinitiate the logger object between the events!
See log_40469_new_instance.py
History
Date User Action Args
2021-08-10 09:00:11martonivansetrecipients: + martonivan, vinay.sajip, markhallett
2021-08-10 09:00:11martonivansetmessageid: <1628586011.3.0.535246252938.issue40469@roundup.psfhosted.org>
2021-08-10 09:00:11martonivanlinkissue40469 messages
2021-08-10 09:00:10martonivancreate