The logging module contains a TimedRotatingFileHandler that automaticly rotates the logfile after a specified interval. This class misses an important feature: it is not possible to specify at what time the file should be rotated, unless that time is midnight. My usecase: one of our customers works night shifts which means that rotating logfiles at midnight means that files get rotated halfway through a shift instead of at the end of one. We'd like to be able to specify that logfiles get rotated at a specific time (such as 7:00AM).
One way of implementing this is to use an additional optional "atTime" parameter which is a datetime.time instance, defaulting to None; a specified value would only be used if a 'when' value of 'D' or 'MIDNIGHT' were specified. In that case, computeRollover would be called with the specified time instead of the current time. Would that meet your requirements?
An 'atTime' argument would work. I'm currently using a subclass of BaseRotatingHandler that implements just the 'MIDNIGHT' option of TimedRotatingFileHandler with a rotation hour argument. The attached patch is a first attempt at implementing the 'atTime' option, it is currently lacking documentation and tests for the 'WEEKLY' value for 'when'.