Package logging :: Module handlers :: Class TimedRotatingFileHandler
[show private | hide private]
[frames | no frames]

Class TimedRotatingFileHandler

Filterer --+                
           |                
     Handler --+            
               |            
   StreamHandler --+        
                   |        
         FileHandler --+    
                       |    
     BaseRotatingHandler --+
                           |
                          TimedRotatingFileHandler


Handler for logging to a file, rotating the log file at certain timed intervals.

If backupCount is > 0, when rollover is done, no more than backupCount files are kept - the oldest ones are deleted.
Method Summary
  __init__(self, filename, when, interval, backupCount, encoding)
  doRollover(self)
do a rollover; in this case, a date/time stamp is appended to the filename when the rollover happens.
  shouldRollover(self, record)
Determine if rollover should occur
    Inherited from BaseRotatingHandler
  emit(self, record)
Emit a record.
    Inherited from FileHandler
  close(self)
Closes the stream.
    Inherited from StreamHandler
  flush(self)
Flushes the stream.
    Inherited from Handler
  acquire(self)
Acquire the I/O thread lock.
  createLock(self)
Acquire a thread lock for serializing access to the underlying I/O.
  format(self, record)
Format the specified record.
  handle(self, record)
Conditionally emit the specified logging record.
  handleError(self, record)
Handle errors which occur during an emit() call.
  release(self)
Release the I/O thread lock.
  setFormatter(self, fmt)
Set the formatter for this handler.
  setLevel(self, level)
Set the logging level of this handler.
    Inherited from Filterer
  addFilter(self, filter)
Add the specified filter to this handler.
  filter(self, record)
Determine if a record is loggable by consulting all the filters.
  removeFilter(self, filter)
Remove the specified filter from this handler.

Method Details

__init__(self, filename, when='h', interval=1, backupCount=0, encoding=None)
(Constructor)

Overrides:
logging.handlers.BaseRotatingHandler.__init__

doRollover(self)

do a rollover; in this case, a date/time stamp is appended to the filename when the rollover happens. However, you want the file to be named for the start of the interval, not the current time. If there is a backup count, then we have to get a list of matching filenames, sort them and remove the one with the oldest suffix.

shouldRollover(self, record)

Determine if rollover should occur

record is not used, as we are just comparing times, but it is needed so the method siguratures are the same