Logging exceptions to a file

Stephen Hansen apt.shansen at gmail.com
Thu May 7 12:46:11 EDT 2009


>
>
>  > > So far so good, but I'd like to record (possibly unhandled) exceptions
> > > in the logfile.
> > > * Do I need to explicitly trap every single exception ?
> > > * In that case, won't I get 2 log messages on the console (as
> > > illustrated in the code below:
>

Check out sys.excepthook, something vaguely like:

import sys

def handle_exceptions(exctype, value, traceback):     logging.exception("An
unhandled exception was detected.")

sys.excepthook = handle_exceptions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090507/09e426dd/attachment.html>


More information about the Python-list mailing list