[Zodb-checkins] CVS: Zope/lib/python/zLOG - FormatException.py:1.7.6.1

Chris Withers chrisw@nipltd.com
Tue, 7 Jan 2003 05:28:31 -0500


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

Modified Files:
      Tag: Zope-2_6-branch
	FormatException.py 
Log Message:
Collector #730: Exceptions are once more logged with their
        tracebacks.

=== Zope/lib/python/zLOG/FormatException.py 1.7 => 1.7.6.1 ===
--- Zope/lib/python/zLOG/FormatException.py:1.7	Wed Aug 14 18:12:33 2002
+++ Zope/lib/python/zLOG/FormatException.py	Tue Jan  7 05:28:27 2003
@@ -2,20 +2,52 @@
 #
 # Copyright (c) 2001, 2002 Zope Corporation and Contributors.
 # All Rights Reserved.
-#
+# 
 # This software is subject to the provisions of the Zope Public License,
 # Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE
-#
+# 
 ##############################################################################
 __version__='$Revision$'[11:-2]
 
-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
+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)