6.28.5.4 TimedRotatingFileHandler

The TimedRotatingFileHandler class supports rotation of disk log files at certain timed intervals.

class TimedRotatingFileHandler( filename [,when [,interval [,backupCount]]])

Returns a new instance of the TimedRotatingFileHandler class. The specified file is opened and used as the stream for logging. On rotating it also sets the filename suffix. Rotating happens based on the product of when and interval.

You can use the when to specify the type of interval. The list of possible values is, note that they are not case sensitive:

Value Type of interval
S Seconds
M Minutes
H Hours
D Days
W Week day (0=Monday)
midnight Roll over at midnight

If backupCount is non-zero, the system will save old log files by appending the extensions ".1", ".2" etc., to the filename. For example, with a backupCount of 5 and a base file name of app.log, you would get app.log, app.log.1, app.log.2, up to app.log.5. The file being written to is always app.log. When this file is filled, it is closed and renamed to app.log.1, and if files app.log.1, app.log.2, etc. exist, then they are renamed to app.log.2, app.log.3 etc. respectively.

doRollover( )
Does a rollover, as described above.

emit( record)
Outputs the record to the file, catering for rollover as described above.

See About this document... for information on suggesting changes.