[Twisted-Python] passing exception object to log.err doesn't log traceback?

Itamar Turner-Trauring itamar at futurefoundries.com
Thu Nov 15 09:56:44 EST 2012

On Thu, Nov 15, 2012 at 9:02 AM, Paul Wiseman <poalman at gmail.com> wrote:

> I was just looking at some logs and some of the errors logged without
> tracebacks, I work out it was when I wasn't passing the error object to
> log.err- Is this by design?

In Python 2.x, exception objects do not have any reference to their
traceback; this is one of the reasons Twisted has the Failure class, which
encapsulates both. (In Python 3 exceptions do have their tracebacks
attached.) Thus, if you want the traceback logged, you should do something

from twisted.python import log

except Exception as e:
    # Log the last exception that occurred, including its traceback:
    log.err(None, "An error occurred.")


from twisted.python import log, failure

except Exception as e:
    f = failure.Failure()
    log.err(f, "An error occurred.")

Itamar Turner-Trauring, Future Foundries LLC
http://futurefoundries.com/ — Twisted consulting, training and support.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20121115/def4111b/attachment.htm 

More information about the Twisted-Python mailing list