handlers.SocketHandler and exceptions

Mark Tolonen mark.e.tolonen at mailinator.com
Wed Jan 16 21:42:55 EST 2008


"writeson" <doug.farrell at gmail.com> wrote in message 
news:02de2e9c-331d-45c0-afaa-578ddad55664 at j78g2000hsd.googlegroups.com...
> Hi all,
>
> On our Linux systems at work I've written a Twisted logging server
> that receives log messages from multiple servers/processes to post
> them to a log file, essentially serializing all the process log
> messages. This works well, that is until I tried this test code:
>
> try:
>    t = 10 / 0
> except Exception, e:
>    log.exception("divide by zero")
>
> where log is the logger instance retreived from a call to getLogger().
> The problem is the handlers.SocketHandler tries to cPickle.dump() the
> log record, which in this case contains an exc_info tuple, the last
> item of which is a Traceback object. The pickling fails with an
> "unpickleable error" and that's that.
>
> Does anyone have any ideas how to handle this situation? I'd hate to
> have to give up using the log.exception(...) call as it's useful to
> get strack trace information in the log file.
>
> Thanks in advance,
> Doug Farrell

Check out the traceback module.  It can translate the traceback into a 
variety of formats (such as a string) that can be pickled.

--Mark 




More information about the Python-list mailing list