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

Class DatagramHandler

Filterer --+        
           |        
     Handler --+    
               |    
   SocketHandler --+
                   |
                  DatagramHandler


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 Summary
  __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.
    Inherited from SocketHandler
  close(self)
Closes the socket.
  createSocket(self)
Try to create a socket, using an exponential backoff with a max retry time.
  emit(self, record)
Emit a record.
  handleError(self, record)
Handle an error during logging.
  makePickle(self, record)
Pickles the record in binary format with a length prefix, and returns it ready for transmission across the socket.
    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.
  format(self, record)
Format the specified record.
  handle(self, record)
Conditionally emit the specified logging record.
  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, host, port)
(Constructor)

Initializes the handler with a specific host address and port.
Overrides:
logging.handlers.SocketHandler.__init__

makeSocket(self)

The factory method of SocketHandler is here overridden to create a UDP socket (SOCK_DGRAM).
Overrides:
logging.handlers.SocketHandler.makeSocket

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.
Overrides:
logging.handlers.SocketHandler.send