getlogbook / logbook

A cool logging replacement for Python.
http://logbook.readthedocs.org
Other
1.48k stars 165 forks source link

TimedRotatingFileHandler append in local time #311

Open Frame42 opened 4 years ago

Frame42 commented 4 years ago

Hi,

I'm trying to set up a TimeRotationgFileHandler to append to one logfile per hour. It works fine in UTC, but if I set the time to local, the log file is overwritten every time.

import logbook

logbook.set_datetime_format("local")

handler1 = logbook.TimedRotatingFileHandler("service.log", date_format="%Y-%m-%d_%H", mode='a')

handler1.push_application()
logbook.Logger("Logger1").info("First trace")
handler1.pop_application()

handler2 = logbook.TimedRotatingFileHandler("service.log", date_format="%Y-%m-%d_%H", mode='a')
handler2.push_application()

logbook.Logger("Logger2").info("Second trace")
handler2.push_application()

Expected Output

[2020-05-04 09:33:22.386174] INFO: Logger1: First trace
[2020-05-04 09:33:22.387136] INFO: Logger2: Second trace

Current Output [2020-05-04 09:33:22.387136] INFO: Logger2: Second trace