[Tutor] Exceptions: Logging TB and local variables?

Kent Johnson kent37 at tds.net
Wed Oct 10 14:22:47 CEST 2007

Allen Fowler wrote:
> In the error log, I would like to record a stacktrace and various local 
> variables that existed in subX at the time the Exception was thrown... 

The stack trace is easy - add the parameter exc_info=True to the logging 
call, e.g.
   logging.error('Oops!', exc_info=True)

When you to this the traceback is included in the log message.

For the local variables, you have to do some work yourself. You might 
look at IPython, it has an option to show local variables in the 
post-mortem stack traces, maybe you could take some code from there. See 
the ultraTB module.


More information about the Tutor mailing list