c.l.s._.WatchedFileHandler(logging.FileHandler) : class documentation

Part of canonical.launchpad.scripts View In Hierarchy

A handler for logging to a file, which watches the file to see if it has changed while in use. This can happen because of usage of programs such as newsyslog and logrotate which perform log file rotation. This handler, intended for use under Unix, watches the file to see if it has changed since the last emit. (A file has changed if its device or inode have changed.) If it has changed, the old file stream is closed, and the file opened to get a new stream.

This handler is not appropriate for use under Windows, because under Windows open files cannot be moved or renamed - logging opens the files with exclusive locks - and so there is no need for such a handler. Furthermore, ST_INO is not supported under Windows; stat always returns zero for this value.

This handler is based on a suggestion and patch by Chad J. Schroeder.

Method __init__ Undocumented
Method emit Emit a record.
Method _open Open the current base file with the (original) mode and encoding.
def __init__(self, filename, mode='a', encoding=None):
Undocumented
def _open(self):
Open the current base file with the (original) mode and encoding. Return the resulting stream.
def emit(self, record):
Emit a record.

First check if the underlying file has changed, and if it has, close the old stream and reopen the file to get the current stream.

API Documentation for Launchpad, generated by pydoctor at 2010-09-27 00:00:11.