Commit 489b7d65 authored by Shane Hathaway's avatar Shane Hathaway

Merged shane-better-tracebacks-branch. The changes are explained in...

Merged shane-better-tracebacks-branch.  The changes are explained in http://dev.zope.org/Wikis/DevSite/Proposals/BetterTracebacks
parent 439280ed
...@@ -11,43 +11,11 @@ ...@@ -11,43 +11,11 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.5 $'[11:-2] __version__='$Revision: 1.6 $'[11:-2]
import sys try:
# Use the exception formatter in zExceptions
format_exception_only = None from zExceptions.ExceptionFormatter import format_exception
except ImportError:
def format_exception(etype, value, tb, limit=None, delimiter='\n', # Not available. Use the basic formatter.
header='', trailer=''): from traceback import format_exception
global format_exception_only
if format_exception_only is None:
import traceback
format_exception_only = traceback.format_exception_only
result=['Traceback (innermost last):']
if header: result.insert(0, header)
if limit is None:
if hasattr(sys, 'tracebacklimit'):
limit = sys.tracebacklimit
n = 0
while tb is not None and (limit is None or n < limit):
f = tb.tb_frame
lineno = tb.tb_lineno
co = f.f_code
filename = co.co_filename
name = co.co_name
locals = f.f_locals
result.append(' File %s, line %d, in %s'
% (filename, lineno, name))
try: result.append(' (Object: %s)' %
locals[co.co_varnames[0]].__name__)
except: pass
try: result.append(' (Info: %s)' %
str(locals['__traceback_info__']))
except: pass
tb = tb.tb_next
n = n+1
result.append(' '.join(format_exception_only(etype, value)))
if trailer: result.append(trailer)
return delimiter.join(result)
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
__version__='$Revision: 1.7 $'[11:-2] __version__='$Revision: 1.8 $'[11:-2]
import os, sys, time import os, sys, time
...@@ -87,8 +87,8 @@ class stupid_log_write: ...@@ -87,8 +87,8 @@ class stupid_log_write:
if error: if error:
try: try:
lines = format_exception(error[0], error[1], error[2], lines = format_exception(error[0], error[1], error[2],
trailer="\n", limit=100) limit=100)
print >> _log_dest, lines print >> _log_dest, ''.join(lines)
except: except:
print >> _log_dest, "%s: %s" % error[:2] print >> _log_dest, "%s: %s" % error[:2]
_log_dest.flush() _log_dest.flush()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment