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 Harry-Lees
Recipients Harry-Lees, aeg, vinay.sajip
Date 2021-08-01.09:35:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The issue appears when the TimedRotatingHandler rolls over to a filename that already exists. Running your bash script, the handler correctly rolls over so you end up with the expected behaviour. This issue arises in the case that there is already a file with the target name, that file will be overwritten when the handler rolls over.

This can be seen clearly if you modify to contain

python3 foo
python3 bar
python3 baz

results are below:

$ python3 --version
Python 3.9.5
$ bash ./
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : foo 2021-08-01T10:14:51.521266
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : bar 2021-08-01T10:14:51.577802
10 14 51
TEST > [INFO] [2021-08-01 10:14:51] : baz 2021-08-01T10:14:51.634795
$ ls | grep .log
$ cat test.log
baz 2021-08-01T10:14:51.634795
$ cat test.log.2021-07-31 
bar 2021-08-01T10:14:51.577802

as you can see, the logs from foo have been overwritten.

A very similar result can be seen if you manually create a file and then run the test script.

$ python3 --version
Python 3.9.5
$ echo "logging test" > test.log.2021-07-31
$ python3 foo
10 33 25
TEST > [INFO] [2021-08-01 10:33:25] : foo 2021-08-01T10:33:25.003750
$ cat test.log
foo 2021-08-01T10:33:25.003750
$ cat test.log.2021-07-31

once again, you can see that the handler overwrote the target file (this time leaving it blank as there were no logs to write).
Date User Action Args
2021-08-01 09:35:10Harry-Leessetrecipients: + Harry-Lees, vinay.sajip, aeg
2021-08-01 09:35:10Harry-Leessetmessageid: <>
2021-08-01 09:35:10Harry-Leeslinkissue44186 messages
2021-08-01 09:35:10Harry-Leescreate