[Zodb-checkins] CVS: Zope/lib/python/zLOG - FormatException.py:1.6 MinimalLogger.py:1.8
Shane Hathaway
shane@cvs.zope.org
Wed, 3 Apr 2002 15:44:02 -0500
Update of /cvs-repository/Zope/lib/python/zLOG
In directory cvs.zope.org:/tmp/cvs-serv3170/lib/python/zLOG
Modified Files:
FormatException.py MinimalLogger.py
Log Message:
Merged shane-better-tracebacks-branch. The changes are explained in http://dev.zope.org/Wikis/DevSite/Proposals/BetterTracebacks
=== Zope/lib/python/zLOG/FormatException.py 1.5 => 1.6 ===
__version__='$Revision$'[11:-2]
-import sys
-
-format_exception_only = None
-
-def format_exception(etype, value, tb, limit=None, delimiter='\n',
- header='', trailer=''):
- 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)
+try:
+ # Use the exception formatter in zExceptions
+ from zExceptions.ExceptionFormatter import format_exception
+except ImportError:
+ # Not available. Use the basic formatter.
+ from traceback import format_exception
=== Zope/lib/python/zLOG/MinimalLogger.py 1.7 => 1.8 ===
try:
lines = format_exception(error[0], error[1], error[2],
- trailer="\n", limit=100)
- print >> _log_dest, lines
+ limit=100)
+ print >> _log_dest, ''.join(lines)
except:
print >> _log_dest, "%s: %s" % error[:2]
_log_dest.flush()