Logging Stacktrace To File

Peter Hansen peter at engcorp.com
Tue Apr 13 08:44:33 EDT 2004


Olaf Meding wrote:

>>... have to catch the exception and then log it to the file.
> 
> 
> Right.  I do also know how to open a file and write to it.
> 
> But how do I get at the stack trace?  I would like to have it look the same
> in the file as what gets printed to the screen.

You're looking for the standard module "traceback", plus possibly
a call to sys.exc_info()...

The Cookbook has some helpful examples, probably more complex than
what you need:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65332

-Peter



More information about the Python-list mailing list