| |
- FileHandler(StreamHandler)
-
- RotatingFileHandler
- Handler(Filterer)
-
- BufferingHandler
-
- MemoryHandler
- HTTPHandler
- NTEventLogHandler
- SMTPHandler
- SocketHandler
-
- DatagramHandler
- SysLogHandler
class BufferingHandler(Handler) |
|
A handler class which buffers logging records in memory. Whenever each
record is added to the buffer, a check is made to see if the buffer should
be flushed. If it should, then flush() is expected to do what's needed. |
|
- Method resolution order:
- BufferingHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, capacity)
- Initialize the handler with the buffer size.
- emit(self, record)
- Emit a record.
Append the record. If shouldFlush() tells us to, call flush() to process
the buffer.
- flush(self)
- Override to implement custom flushing behaviour.
This version just zaps the buffer to empty.
- shouldFlush(self, record)
- Should the handler flush its buffer?
Returns true if the buffer is up to capacity. This method can be
overridden to implement custom flushing strategies.
Methods inherited from Handler:
- acquire(self)
- Acquire the I/O thread lock.
- close(self)
- Tidy up any resources used by the handler.
This version does nothing and is intended to be implemented by
subclasses.
- createLock(self)
- Acquire a thread lock for serializing access to the underlying I/O.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class DatagramHandler(SocketHandler) |
|
A handler class which writes logging records, in pickle format, to
a datagram socket. The pickle which is sent is that of the LogRecord's
attribute dictionary (__dict__), so that the receiver does not need to
have the logging module installed in order to process the logging event.
To unpickle the record at the receiving end into a LogRecord, use the
makeLogRecord function. |
|
- Method resolution order:
- DatagramHandler
- SocketHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, host, port)
- Initializes the handler with a specific host address and port.
- makeSocket(self)
- The factory method of SocketHandler is here overridden to create
a UDP socket (SOCK_DGRAM).
- send(self, s)
- Send a pickled string to a socket.
This function no longer allows for partial sends which can happen
when the network is busy - UDP does not guarantee delivery and
can deliver packets out of sequence.
Methods inherited from SocketHandler:
- close(self)
- Closes the socket.
- emit(self, record)
- Emit a record.
Pickles the record and writes it to the socket in binary format.
If there is an error with the socket, silently drop the packet.
If there was a problem with the socket, re-establishes the
socket.
- handleError(self, record)
- Handle an error during logging.
An error has occurred during logging. Most likely cause -
connection lost. Close the socket so that we can retry on the
next event.
- makePickle(self, record)
- Pickles the record in binary format with a length prefix, and
returns it ready for transmission across the socket.
Methods 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.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class HTTPHandler(Handler) |
|
A class which sends records to a Web server, using either GET or
POST semantics. |
|
- Method resolution order:
- HTTPHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, host, url, method='GET')
- Initialize the instance with the host, the request URL, and the method
("GET" or "POST")
- emit(self, record)
- Emit a record.
Send the record to the Web server as an URL-encoded dictionary
- mapLogRecord(self, record)
- Default implementation of mapping the log record into a dict
that is send as the CGI data. Overwrite in your class.
Contributed by Franz Glasner.
Methods inherited from Handler:
- acquire(self)
- Acquire the I/O thread lock.
- close(self)
- Tidy up any resources used by the handler.
This version does nothing and is intended to be implemented by
subclasses.
- createLock(self)
- Acquire a thread lock for serializing access to the underlying I/O.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class MemoryHandler(BufferingHandler) |
|
A handler class which buffers logging records in memory, periodically
flushing them to a target handler. Flushing occurs whenever the buffer
is full, or when an event of a certain severity or greater is seen. |
|
- Method resolution order:
- MemoryHandler
- BufferingHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, capacity, flushLevel=40, target=None)
- Initialize the handler with the buffer size, the level at which
flushing should occur and an optional target.
Note that without a target being set either here or via setTarget(),
a MemoryHandler is no use to anyone!
- close(self)
- Flush, set the target to None and lose the buffer.
- flush(self)
- For a MemoryHandler, flushing means just sending the buffered
records to the target, if there is one. Override if you want
different behaviour.
- setTarget(self, target)
- Set the target handler for this handler.
- shouldFlush(self, record)
- Check for buffer full or a record at the flushLevel or higher.
Methods inherited from BufferingHandler:
- emit(self, record)
- Emit a record.
Append the record. If shouldFlush() tells us to, call flush() to process
the buffer.
Methods 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.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class NTEventLogHandler(Handler) |
|
A handler class which sends events to the NT Event Log. Adds a
registry entry for the specified application name. If no dllname is
provided, win32service.pyd (which contains some basic message
placeholders) is used. Note that use of these placeholders will make
your event logs big, as the entire message source is held in the log.
If you want slimmer logs, you have to pass in the name of your own DLL
which contains the message definitions you want to use in the event log. |
|
- Method resolution order:
- NTEventLogHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, appname, dllname=None, logtype='Application')
- close(self)
- Clean up this handler.
You can remove the application name from the registry as a
source of event log entries. However, if you do this, you will
not be able to see the events as you intended in the Event Log
Viewer - it needs to be able to access the registry to get the
DLL name.
- emit(self, record)
- Emit a record.
Determine the message ID, event category and event type. Then
log the message in the NT event log.
- getEventCategory(self, record)
- Return the event category for the record.
Override this if you want to specify your own categories. This version
returns 0.
- getEventType(self, record)
- Return the event type for the record.
Override this if you want to specify your own types. This version does
a mapping using the handler's typemap attribute, which is set up in
__init__() to a dictionary which contains mappings for DEBUG, INFO,
WARNING, ERROR and CRITICAL. If you are using your own levels you will
either need to override this method or place a suitable dictionary in
the handler's typemap attribute.
- getMessageID(self, record)
- Return the message ID for the event record. If you are using your
own messages, you could do this by having the msg passed to the
logger being an ID rather than a formatting string. Then, in here,
you could use a dictionary lookup to get the message ID. This
version returns 1, which is the base message ID in win32service.pyd.
Methods 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.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class RotatingFileHandler(FileHandler) |
| |
- Method resolution order:
- RotatingFileHandler
- FileHandler
- StreamHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, filename, mode='a', maxBytes=0, backupCount=0)
- 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.
- doRollover(self)
- Do a rollover, as described in __init__().
- emit(self, record)
- Emit a record.
Output the record to the file, catering for rollover as described
in doRollover().
Methods inherited from FileHandler:
- close(self)
- Closes the stream.
Methods inherited from StreamHandler:
- flush(self)
- Flushes the stream.
Methods 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.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class SMTPHandler(Handler) |
|
A handler class which sends an SMTP email for each logging event. |
|
- Method resolution order:
- SMTPHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, mailhost, fromaddr, toaddrs, subject)
- Initialize the handler.
Initialize the instance with the from and to addresses and subject
line of the email. To specify a non-standard SMTP port, use the
(host, port) tuple format for the mailhost argument.
- date_time(self)
- Return the current date and time formatted for a MIME header.
- emit(self, record)
- Emit a record.
Format the record and send it to the specified addressees.
- getSubject(self, record)
- Determine the subject for the email.
If you want to specify a subject line which is record-dependent,
override this method.
Data and other attributes defined here:
- monthname = [None, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
- weekdayname = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
Methods inherited from Handler:
- acquire(self)
- Acquire the I/O thread lock.
- close(self)
- Tidy up any resources used by the handler.
This version does nothing and is intended to be implemented by
subclasses.
- createLock(self)
- Acquire a thread lock for serializing access to the underlying I/O.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class SocketHandler(Handler) |
|
A handler class which writes logging records, in pickle format, to
a streaming socket. The socket is kept open across logging calls.
If the peer resets it, an attempt is made to reconnect on the next call.
The pickle which is sent is that of the LogRecord's attribute dictionary
(__dict__), so that the receiver does not need to have the logging module
installed in order to process the logging event.
To unpickle the record at the receiving end into a LogRecord, use the
makeLogRecord function. |
|
- Method resolution order:
- SocketHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, host, port)
- Initializes the handler with a specific host address and port.
The attribute 'closeOnError' is set to 1 - which means that if
a socket error occurs, the socket is silently closed and then
reopened on the next logging call.
- close(self)
- Closes the socket.
- emit(self, record)
- Emit a record.
Pickles the record and writes it to the socket in binary format.
If there is an error with the socket, silently drop the packet.
If there was a problem with the socket, re-establishes the
socket.
- handleError(self, record)
- Handle an error during logging.
An error has occurred during logging. Most likely cause -
connection lost. Close the socket so that we can retry on the
next event.
- makePickle(self, record)
- Pickles the record in binary format with a length prefix, and
returns it ready for transmission across the socket.
- makeSocket(self)
- A factory method which allows subclasses to define the precise
type of socket they want.
- send(self, s)
- Send a pickled string to the socket.
This function allows for partial sends which can happen when the
network is busy.
Methods 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.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
|
class SysLogHandler(Handler) |
|
A handler class which sends formatted logging records to a syslog
server. Based on Sam Rushing's syslog module:
http://www.nightmare.com/squirl/python-ext/misc/syslog.py
Contributed by Nicolas Untz (after which minor refactoring changes
have been made). |
|
- Method resolution order:
- SysLogHandler
- Handler
- Filterer
Methods defined here:
- __init__(self, address=('localhost', 514), facility=1)
- Initialize a handler.
If address is specified as a string, UNIX socket is used.
If facility is not specified, LOG_USER is used.
- close(self)
- Closes the socket.
- emit(self, record)
- Emit a record.
The record is formatted, and then sent to the syslog server. If
exception information is present, it is NOT sent to the server.
- encodePriority(self, facility, priority)
- Encode the facility and priority. You can pass in strings or
integers - if strings are passed, the facility_names and
priority_names mapping dictionaries are used to convert them to
integers.
Data and other attributes defined here:
- LOG_ALERT = 1
- LOG_AUTH = 4
- LOG_AUTHPRIV = 10
- LOG_CRIT = 2
- LOG_CRON = 9
- LOG_DAEMON = 3
- LOG_DEBUG = 7
- LOG_EMERG = 0
- LOG_ERR = 3
- LOG_INFO = 6
- LOG_KERN = 0
- LOG_LOCAL0 = 16
- LOG_LOCAL1 = 17
- LOG_LOCAL2 = 18
- LOG_LOCAL3 = 19
- LOG_LOCAL4 = 20
- LOG_LOCAL5 = 21
- LOG_LOCAL6 = 22
- LOG_LOCAL7 = 23
- LOG_LPR = 6
- LOG_MAIL = 2
- LOG_NEWS = 7
- LOG_NOTICE = 5
- LOG_SYSLOG = 5
- LOG_USER = 1
- LOG_UUCP = 8
- LOG_WARNING = 4
- facility_names = {'auth': 4, 'authpriv': 10, 'cron': 9, 'daemon': 3, 'kern': 0, 'local0': 16, 'local1': 17, 'local2': 18, 'local3': 19, 'local4': 20, ...}
- log_format_string = '<%d>%s\x00'
- priority_names = {'alert': 1, 'crit': 2, 'critical': 2, 'debug': 7, 'emerg': 0, 'err': 3, 'error': 3, 'info': 6, 'notice': 5, 'panic': 0, ...}
Methods 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.
- flush(self)
- Ensure all logging output has been flushed.
This version does nothing and is intended to be implemented by
subclasses.
- format(self, record)
- Format the specified record.
If a formatter is set, use it. Otherwise, use the default formatter
for the module.
- handle(self, record)
- Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
- handleError(self, record)
- Handle errors which occur during an emit() call.
This method should be called from handlers when an exception is
encountered during an emit() call. If raiseExceptions is false,
exceptions get silently ignored. This is what is mostly wanted
for a logging system - most users will not care about errors in
the logging system, they are more interested in application errors.
You could, however, replace this with a custom handler if you wish.
The record which was being processed is passed in to this method.
- 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.
Methods 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.
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
- removeFilter(self, filter)
- Remove the specified filter from this handler.
| |