Go to the latest version of this document.

# ``twisted`.`python`.`logfile`.`LogFile``

class documentation

`class LogFile(BaseLogFile): (source)`

Constructor: `LogFile(name, directory, rotateLength, defaultMode, maxRotatedFiles)`

View In Hierarchy

A log file that can be rotated.

A rotateLength of None disables automatic log rotation.

Method | `__getstate__` | Undocumented
Method | `__init__` | Create a log file rotating on length.
Method | `getLog` | Given an integer, return a LogReader for an old log file.
Method | `listLogs` | Return sorted list of integers - the old logs' identifiers.
Method | `rotate` | Rotate the file and create a new one.
Method | `shouldRotate` | Rotate when the log file size is larger than rotateLength.
Method | `write` | Write some data to the file.
Instance Variable | `maxRotatedFiles` | Undocumented
Instance Variable | `rotateLength` | Undocumented
Instance Variable | `size` | Undocumented
Method | `_openFile` | Open the log file.

Inherited from `BaseLogFile`:

Class Method | `fromFullPath` | Construct a log file from a full file path.
Method | `close` | Close the file.
Method | `flush` | Flush the file.
Method | `getCurrentLog` | Return a LogReader for the current log file.
Method | `reopen` | Reopen the log file. This is mainly useful if you use an external log rotation tool, which moves under your feet.
Class Variable | `synchronized` | Undocumented
Instance Variable | `closed` | Undocumented
Instance Variable | `defaultMode` | Undocumented
Instance Variable | `directory` | Undocumented
Instance Variable | `name` | Undocumented
Instance Variable | `path` | Undocumented
Instance Variable | `_file` | Undocumented

def __getstate__(self): (source)

Undocumented

def __init__(self, name, directory, rotateLength=1000000, defaultMode=None, maxRotatedFiles=None): (source)
overrides `twisted.python.logfile.BaseLogFile.__init__`

Create a log file rotating on length.

Parameters
name:`str` | file name.
directory:`str` | path of the log file.
rotateLength:`int` | size of the log file where it rotates. Default to 1M.
defaultMode:`int` | mode used to create the file.
maxRotatedFiles:`int` | if not None, max number of log files the class creates. Warning: it removes all log files above this number.

def getLog(self, identifier): (source)

Given an integer, return a LogReader for an old log file.

def listLogs(self): (source)

Return sorted list of integers - the old logs' identifiers.

def rotate(self): (source)

Rotate the file and create a new one.

If it's not possible to open new logfile, this will fail silently, and continue logging to old logfile.

def shouldRotate(self): (source)
overrides `twisted.python.logfile.BaseLogFile.shouldRotate`

Rotate when the log file size is larger than rotateLength.

def write(self, data): (source)
overrides `twisted.python.logfile.BaseLogFile.write`

Write some data to the file.

maxRotatedFiles = (source)

Undocumented

rotateLength = (source)

Undocumented

size = (source)

Undocumented

def _openFile(self): (source)
overrides `twisted.python.logfile.BaseLogFile._openFile`

Open the log file.

The log file is always opened in binary mode.