Open aczapszys opened 5 years ago
Thanks for reporting! If you can come up with an example test that demonstrates the bug and a PR for fixing it, I'll gladly review and merge it.
I have also encountered a similar problem with TimedRotatingFileHandler. It occurs only when logbook.set_datetime_format("local")
is used. According to the description of this bug, the cause might be the same.
My problem can be reproduced like this (for timezone ahead of UTC):
1/ Wait until local time rolls over midnight, so now the date is different in UTC zone (e.g. 01.11.2018) and local zone (e.g. 02.11.2018).
2/ Run the application. It creates a new logfile named after the local date (e.g. app-2018-11-02.log). The file contains correct logging data.
3/ Run the application again. The current logfile (app-2018-11-02.log) is rewritten, data are not appended. The file contains only data from the second run. -> BUG
The previous logfile (app-2018-11-01.log) is not touched.
If the local time and UTC time have the same date, the logfile is appended correctly.
In our local app we're using localtime cem/utilities/logger.py: logbook.set_datetime_format('local')
But in TimedRotatingFileHandler, the default "now" is utcnow. So, TimedRotatingFileHandler.init computes
After calling
logbook.set_datetime_format('local')
, here's what the factories look like.Here's a possible approach to make this work as expected: