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

Class RotatingFileHandler

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


Handler for logging to a set of files, which switches from one file to the next when the current file reaches a certain size.
Method Summary
  __init__(self, filename, mode, maxBytes, backupCount, encoding)
Open the specified file and use it as the stream for logging.
  doRollover(self)
Do a rollover, as described in __init__().
  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, mode='a', maxBytes=0, backupCount=0, encoding=None)
(Constructor)

Open the specified file and use it as the stream for logging.

By default, the file grows indefinitely. You can specify particular values of maxBytes and backupCount to allow the file to rollover at a predetermined size.

Rollover occurs whenever the current log file is nearly maxBytes in length. If backupCount is >= 1, the system will successively create new files with the same pathname as the base file, but with extensions ".1", ".2" etc. appended to it. 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", ... through to "app.log.5". The file being written to is always "app.log" - when it gets filled up, 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.

If maxBytes is zero, rollover never occurs.
Overrides:
logging.handlers.BaseRotatingHandler.__init__

doRollover(self)

Do a rollover, as described in __init__().

shouldRollover(self, record)

Determine if rollover should occur.

Basically, see if the supplied record would cause the file to exceed the size limit we have.