Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
logging.handlers.QueueHandler Class Reference

List of all members.

Public Member Functions

def __init__
def enqueue
def prepare
def emit

Public Attributes

 queue

Detailed Description

This handler sends events to a queue. Typically, it would be used together
with a multiprocessing Queue to centralise logging to file in one process
(in a multi-process application), so as to avoid file write contention
between processes.

This code is new in Python 3.2, but this class can be copy pasted into
user code for use with earlier Python versions.

Definition at line 1162 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.QueueHandler.__init__ (   self,
  queue 
)
Initialise an instance, using the passed queue.

Definition at line 1173 of file handlers.py.

01173 
01174     def __init__(self, queue):
01175         """
01176         Initialise an instance, using the passed queue.
01177         """
01178         logging.Handler.__init__(self)
01179         self.queue = queue

Here is the caller graph for this function:


Member Function Documentation

def logging.handlers.QueueHandler.emit (   self,
  record 
)
Emit a record.

Writes the LogRecord to the queue, preparing it for pickling first.

Definition at line 1215 of file handlers.py.

01215 
01216     def emit(self, record):
01217         """
01218         Emit a record.
01219 
01220         Writes the LogRecord to the queue, preparing it for pickling first.
01221         """
01222         try:
01223             self.enqueue(self.prepare(record))
01224         except (KeyboardInterrupt, SystemExit):
01225             raise
01226         except:
01227             self.handleError(record)

Here is the call graph for this function:

def logging.handlers.QueueHandler.enqueue (   self,
  record 
)
Enqueue a record.

The base implementation uses put_nowait. You may want to override
this method if you want to use blocking, timeouts or custom queue
implementations.

Definition at line 1180 of file handlers.py.

01180 
01181     def enqueue(self, record):
01182         """
01183         Enqueue a record.
01184 
01185         The base implementation uses put_nowait. You may want to override
01186         this method if you want to use blocking, timeouts or custom queue
01187         implementations.
01188         """
01189         self.queue.put_nowait(record)

Here is the caller graph for this function:

def logging.handlers.QueueHandler.prepare (   self,
  record 
)
Prepares a record for queuing. The object returned by this method is
enqueued.

The base implementation formats the record to merge the message
and arguments, and removes unpickleable items from the record
in-place.

You might want to override this method if you want to convert
the record to a dict or JSON string, or send a modified copy
of the record while leaving the original intact.

Definition at line 1190 of file handlers.py.

01190 
01191     def prepare(self, record):
01192         """
01193         Prepares a record for queuing. The object returned by this method is
01194         enqueued.
01195 
01196         The base implementation formats the record to merge the message
01197         and arguments, and removes unpickleable items from the record
01198         in-place.
01199 
01200         You might want to override this method if you want to convert
01201         the record to a dict or JSON string, or send a modified copy
01202         of the record while leaving the original intact.
01203         """
01204         # The format operation gets traceback text into record.exc_text
01205         # (if there's exception data), and also puts the message into
01206         # record.message. We can then use this to replace the original
01207         # msg + args, as these might be unpickleable. We also zap the
01208         # exc_info attribute, as it's no longer needed and, if not None,
01209         # will typically not be pickleable.
01210         self.format(record)
01211         record.msg = record.message
01212         record.args = None
01213         record.exc_info = None
01214         return record

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1178 of file handlers.py.


The documentation for this class was generated from the following file: