Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!q20g2000vbx.googlegroups.com!not-for-mail From: Vinay Sajip Newsgroups: comp.lang.python Subject: Re: unpickling derived LogRecord in python 2.7 from python2.6 Date: Wed, 27 Apr 2011 13:39:08 -0700 (PDT) Organization: http://groups.google.com Lines: 29 Message-ID: References: NNTP-Posting-Host: 82.152.15.113 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1303936749 32132 127.0.0.1 (27 Apr 2011 20:39:09 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Apr 2011 20:39:09 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q20g2000vbx.googlegroups.com; posting-host=82.152.15.113; posting-account=3PSTgxAAAACRZBfTFqcrp20l4rsi4Aaz User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4162 On Apr 27, 5:41=A0pm, Peter Otten <__pete...@web.de> wrote: > The Problem is that as of Python 2.7logging.LogRecord has become a newsty= le > class which is pickled/unpickled differently. I don't know if there is an > official way to do the conversion, but here's what I've hacked up. > The script can read pickles written with 2.6 in 2.7, but not the other wa= y > round. > [code snipped] I don't know about "official", but another way of doing this is to pickle just the LogRecord's __dict__ and send that over the wire. The logging package contains a function makeLogRecord(d) where d is a dict. This is the approach used by the examples in the library documentation which pickle events for sending across a network: http://docs.python.org/howto/logging-cookbook.html#sending-and-receiving-lo= gging-events-across-a-network The built-in SocketHandler pickles the LogRecord's __dict__ rather than the LogRecord itself, precisely because of the improved interoperability over pickling the instance directly. Regards, Vinay Sajip