def log_traceback_from_info(exception_type, value, tb, dst=sys.stderr, skip=0):
"""Log a given exception nicely to 'dst', showing a traceback.
dst -- writeable file-like object
skip -- number of traceback entries to omit from the top of the list
"""
for line in traceback.format_exception_only(exception_type, value):
dst.write(line)
if (not isinstance(exception_type, str) and
issubclass(exception_type, SyntaxError)):
return
print >>dst, 'traceback (most recent call last):'
text = None
for filename, lineno, fnname, text in traceback.extract_tb(tb)[skip:]:
if fnname == "?":
fn_s = "<global scope>"
else:
fn_s = "(%s)" % fnname
print >>dst, " %s:%s %s" % (filename, lineno, fn_s)
if text is not None:
print >>dst, "failing line:"
print >>dst, text
评论列表
文章目录