[Zope-Checkins] CVS: Zope/lib/python/zLOG - FormatException.py:1.4.2.1 MinimalLogger.py:1.6.2.1

Shane Hathaway shane@cvs.zope.org
Tue, 2 Apr 2002 18:07:22 -0500


Update of /cvs-repository/Zope/lib/python/zLOG
In directory cvs.zope.org:/tmp/cvs-serv671

Modified Files:
      Tag: shane-better-tracebacks-branch
	FormatException.py MinimalLogger.py 
Log Message:
Corrected signature of format_exception() and made zLOG use the exception
formatter if available.


=== Zope/lib/python/zLOG/FormatException.py 1.4 => 1.4.2.1 ===
 __version__='$Revision$'[11:-2]
 
-import string, 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(string.join(format_exception_only(etype, value),
-                              ' '))
-    if trailer: result.append(trailer)
-    
-    return string.join(result, delimiter)
+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.6 => 1.6.2.1 ===
             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()