[Python-bugs-list] [ python-Bugs-760703 ] SocketHandler and LogRecord don't work well

SourceForge.net noreply@sourceforge.net
Wed, 25 Jun 2003 11:56:15 -0700


Bugs item #760703, was opened at 2003-06-25 12:56
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=760703&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Jason R. Coombs (jaraco)
Assigned to: Nobody/Anonymous (nobody)
Summary: SocketHandler and LogRecord don't work well

Initial Comment:
>From the logging module, I'm using the DatagramHandler 
(or SocketHandler) to send log messages via UDP 665.  
When I receive them on the other side, there's no 
elegant way to reconstruct them on the other side.  For 
example,

--- in one python session ---
>>> import logging, logging.handlers
>>> handler = logging.handlers.DatagramHandler
( 'localhost', 695 )
>>> logging.root.addHandler( handler )
>>> logging.root.info( 'test' )

--- and in another ---
>>> from socket import *
>>> import pickle, logging
>>> s = socket( AF_INET, SOCK_DGRAM )
>>> s.bind( ( '', 695 ) )
>>> rec = s.recv( 32768 )[4:] #ignore length for now
>>> rec = pickle.loads( rec )
>>> type( rec )
<type 'dict'>
>>> newRec = logging.LogRecord( '', '', '', 1, '', (), None )
>>> newRec.__dict__ = rec

Because logging.LogRecord is not a dict or derived from 
dict, I have to create a log record using 7 arguments, 
then assign the unpickled dict... which is not pretty to 
say the least.

Furthermore, the documentation dictates that the 
record is pickled, not the record's __dict__.

I changed line 163 in logging.handlers to:
        s = cPickle.dumps( record, 1 )
from
        s = cPickle.dumps(record.__dict__, 1)

And I think this is the way it should be done, both to be 
consistent with the documentation, and to make 
reconstruction on the far end more elegant and intuitive.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=760703&group_id=5470