Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
logging.handlers.DatagramHandler Class Reference
Inheritance diagram for logging.handlers.DatagramHandler:
Inheritance graph
[legend]
Collaboration diagram for logging.handlers.DatagramHandler:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def makeSocket
def send
def makeSocket
def createSocket
def makePickle
def handleError
def emit
def close

Public Attributes

 closeOnError
 host
 port
 sock
 retryTime
 retryStart
 retryMax
 retryFactor
 retryPeriod

Detailed Description

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.

Definition at line 562 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.DatagramHandler.__init__ (   self,
  host,
  port 
)
Initializes the handler with a specific host address and port.

Reimplemented from logging.handlers.SocketHandler.

Definition at line 573 of file handlers.py.

00573 
00574     def __init__(self, host, port):
00575         """
00576         Initializes the handler with a specific host address and port.
00577         """
00578         SocketHandler.__init__(self, host, port)
00579         self.closeOnError = 0

Here is the caller graph for this function:


Member Function Documentation

def logging.handlers.SocketHandler.close (   self) [inherited]
Closes the socket.

Definition at line 553 of file handlers.py.

00553 
00554     def close(self):
00555         """
00556         Closes the socket.
00557         """
00558         if self.sock:
00559             self.sock.close()
00560             self.sock = None
00561         logging.Handler.close(self)

Here is the caller graph for this function:

def logging.handlers.SocketHandler.createSocket (   self) [inherited]
Try to create a socket, using an exponential backoff with
a max retry time. Thanks to Robert Olson for the original patch
(SF #815911) which has been slightly refactored.

Definition at line 452 of file handlers.py.

00452 
00453     def createSocket(self):
00454         """
00455         Try to create a socket, using an exponential backoff with
00456         a max retry time. Thanks to Robert Olson for the original patch
00457         (SF #815911) which has been slightly refactored.
00458         """
00459         now = time.time()
00460         # Either retryTime is None, in which case this
00461         # is the first time back after a disconnect, or
00462         # we've waited long enough.
00463         if self.retryTime is None:
00464             attempt = 1
00465         else:
00466             attempt = (now >= self.retryTime)
00467         if attempt:
00468             try:
00469                 self.sock = self.makeSocket()
00470                 self.retryTime = None # next time, no delay before trying
00471             except socket.error:
00472                 #Creation failed, so set the retry time and return.
00473                 if self.retryTime is None:
00474                     self.retryPeriod = self.retryStart
00475                 else:
00476                     self.retryPeriod = self.retryPeriod * self.retryFactor
00477                     if self.retryPeriod > self.retryMax:
00478                         self.retryPeriod = self.retryMax
00479                 self.retryTime = now + self.retryPeriod

Here is the call graph for this function:

Here is the caller graph for this function:

def logging.handlers.SocketHandler.emit (   self,
  record 
) [inherited]
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.

Definition at line 536 of file handlers.py.

00536 
00537     def emit(self, record):
00538         """
00539         Emit a record.
00540 
00541         Pickles the record and writes it to the socket in binary format.
00542         If there is an error with the socket, silently drop the packet.
00543         If there was a problem with the socket, re-establishes the
00544         socket.
00545         """
00546         try:
00547             s = self.makePickle(record)
00548             self.send(s)
00549         except (KeyboardInterrupt, SystemExit):
00550             raise
00551         except:
00552             self.handleError(record)

Here is the call graph for this function:

def logging.handlers.SocketHandler.handleError (   self,
  record 
) [inherited]
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.

Definition at line 522 of file handlers.py.

00522 
00523     def handleError(self, record):
00524         """
00525         Handle an error during logging.
00526 
00527         An error has occurred during logging. Most likely cause -
00528         connection lost. Close the socket so that we can retry on the
00529         next event.
00530         """
00531         if self.closeOnError and self.sock:
00532             self.sock.close()
00533             self.sock = None        #try to reconnect next time
00534         else:
00535             logging.Handler.handleError(self, record)

Here is the caller graph for this function:

def logging.handlers.SocketHandler.makePickle (   self,
  record 
) [inherited]
Pickles the record in binary format with a length prefix, and
returns it ready for transmission across the socket.

Definition at line 507 of file handlers.py.

00507 
00508     def makePickle(self, record):
00509         """
00510         Pickles the record in binary format with a length prefix, and
00511         returns it ready for transmission across the socket.
00512         """
00513         ei = record.exc_info
00514         if ei:
00515             dummy = self.format(record) # just to get traceback text into record.exc_text
00516             record.exc_info = None  # to avoid Unpickleable error
00517         s = pickle.dumps(record.__dict__, 1)
00518         if ei:
00519             record.exc_info = ei  # for next handler
00520         slen = struct.pack(">L", len(s))
00521         return slen + s

Here is the call graph for this function:

Here is the caller graph for this function:

def logging.handlers.SocketHandler.makeSocket (   self,
  timeout = 1 
) [inherited]
A factory method which allows subclasses to define the precise
type of socket they want.

Definition at line 441 of file handlers.py.

00441 
00442     def makeSocket(self, timeout=1):
00443         """
00444         A factory method which allows subclasses to define the precise
00445         type of socket they want.
00446         """
00447         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
00448         if hasattr(s, 'settimeout'):
00449             s.settimeout(timeout)
00450         s.connect((self.host, self.port))
00451         return s

Here is the caller graph for this function:

The factory method of SocketHandler is here overridden to create
a UDP socket (SOCK_DGRAM).

Definition at line 580 of file handlers.py.

00580 
00581     def makeSocket(self):
00582         """
00583         The factory method of SocketHandler is here overridden to create
00584         a UDP socket (SOCK_DGRAM).
00585         """
00586         s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
00587         return s

def logging.handlers.DatagramHandler.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.

Reimplemented from logging.handlers.SocketHandler.

Definition at line 588 of file handlers.py.

00588 
00589     def send(self, s):
00590         """
00591         Send a pickled string to a socket.
00592 
00593         This function no longer allows for partial sends which can happen
00594         when the network is busy - UDP does not guarantee delivery and
00595         can deliver packets out of sequence.
00596         """
00597         if self.sock is None:
00598             self.createSocket()
00599         self.sock.sendto(s, (self.host, self.port))

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Reimplemented from logging.handlers.SocketHandler.

Definition at line 578 of file handlers.py.

Definition at line 429 of file handlers.py.

Definition at line 430 of file handlers.py.

Definition at line 439 of file handlers.py.

Definition at line 438 of file handlers.py.

Definition at line 473 of file handlers.py.

Definition at line 437 of file handlers.py.

Definition at line 433 of file handlers.py.

Definition at line 431 of file handlers.py.


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