traceback as string

Colin Brown cbrown at metservice.com
Tue Dec 16 14:25:51 EST 2003


"John Hunter" <jdhunter at ace.bsd.uchicago.edu> wrote in message
news:mailman.202.1071593230.9307.python-list at python.org...
>
> What is the best way to get the traceback as a string.

I define the following module "Excepts.py" for logging exceptions in daemon
processes:

------------------------------------------
import sys,traceback

def error():
    tb =
traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.exc_info(
)[2])
    return tb[len(tb)-1].replace('\n','')

def errorstack():
    return
''.join(traceback.format_exception(sys.exc_info()[0],sys.exc_info()[1],sys.e
xc_info()[2]))
-------------------------------------------

Colin Brown
PyNZ






More information about the Python-list mailing list