<br><br><div class="gmail_quote">On Thu, Nov 15, 2012 at 9:02 AM, Paul Wiseman <span dir="ltr">&lt;<a href="mailto:poalman@gmail.com" target="_blank">poalman@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was just looking at some logs and some of the errors logged without tracebacks, I work out it was when I wasn&#39;t passing the error object to log.err- Is this by design?<br></blockquote><div><br>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 like:<br>
<br><div style="margin-left:40px"><font face="courier new,monospace">from twisted.python import log<br><br>try:<br>    1/0<br>except Exception as e:<br>    # Log the last exception that occurred, including its traceback:<br>
    log.err(None, &quot;An error occurred.&quot;)<br></font></div> <br>Or:<br><br><div style="margin-left:40px"><font face="courier new,monospace">from twisted.python import log, failure<br><br>try:<br>    1/0<br>except Exception as e:<br>
    f = failure.Failure()<br>    log.err(f, &quot;An error occurred.&quot;)<br></font></div> <br></div></div>-- <br>Itamar Turner-Trauring, Future Foundries LLC<br><a href="http://futurefoundries.com/" target="_blank">http://futurefoundries.com/</a> — Twisted consulting, training and support.<br>
<br>