TimedRotatingFileHandler

December 2011 ยท 1 minute read

(For future reference.)

TimedRotatingFileHandler logs messages to a file and rotates it based on time values.

Among the arguments it accepts is the when argument, which specifies the type of interval. One of the possible values is 'W', which specifies that the rollover should be done on a specific day of the week (with 0 being Monday). The day is specified by appending the necessary number ([0-6]) to when, like W0 for rotating the logs on Mondays.

The relevant code from logging.handler:

elif self.when.startswith('W'):
    self.interval = 60 * 60 * 24 * 7 # one week
    if len(self.when) != 2:
        raise ValueError(...)
    if self.when[1]  '6':
        raise ValueError(...)
    self.dayOfWeek = int(self.when[1])