Package Ganga :: Package Utility :: Package external :: Package logging :: Module handlers :: Class SocketHandler
[hide private]
[frames] | no frames]

Class SocketHandler

source code

Filterer --+    
           |    
     Handler --+
               |
              SocketHandler
Known Subclasses:

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.

Instance Methods [hide private]
 
__init__(self, host, port)
Initializes the handler with a specific host address and port.
source code
 
makeSocket(self)
A factory method which allows subclasses to define the precise type of socket they want.
source code
 
createSocket(self)
Try to create a socket, using an exponential backoff with a max retry time.
source code
 
send(self, s)
Send a pickled string to the socket.
source code
 
makePickle(self, record)
Pickles the record in binary format with a length prefix, and returns it ready for transmission across the socket.
source code
 
handleError(self, record)
Handle an error during logging.
source code
 
emit(self, record)
Emit a record.
source code
 
close(self)
Closes the socket.
source code

Inherited from Handler: acquire, createLock, flush, format, handle, release, setFormatter, setLevel

Inherited from Filterer: addFilter, filter, removeFilter

Method Details [hide private]

__init__(self, host, port)
(Constructor)

source code 

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.

Overrides: Filterer.__init__

createSocket(self)

source code 

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.

send(self, s)

source code 

Send a pickled string to the socket.

This function allows for partial sends which can happen when the network is busy.

handleError(self, record)

source code 

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.

Overrides: Handler.handleError

emit(self, record)

source code 

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.

Overrides: Handler.emit

close(self)

source code 

Closes the socket.

Overrides: Handler.close