[Zope-Checkins] CVS: Zope3/lib/python/zLOG - FormatException.py:1.7 MinimalLogger.py:1.9 __init__.py:1.6

Jim Fulton jim@zope.com
Mon, 10 Jun 2002 19:30:18 -0400


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

Modified Files:
	FormatException.py MinimalLogger.py __init__.py 
Log Message:
Merged Zope-3x-branch into newly forked Zope3 CVS Tree.

=== Zope3/lib/python/zLOG/FormatException.py 1.6 => 1.7 ===
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# 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 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)


=== Zope3/lib/python/zLOG/MinimalLogger.py 1.8 => 1.9 ===
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
 __version__='$Revision$'[11:-2]
 
-import os,  sys, time
+import os, string, sys, time
 
 from FormatException import format_exception
 
@@ -28,24 +28,24 @@
     }):
     """Convert a severity code to a string
     """
-    s=int(severity)
-    if mapping.has_key(s): s=mapping[s]
-    else: s=''
+    s = int(severity)
+    if mapping.has_key(s):
+        s = mapping[s]
+    else:
+        s = ''
     return "%s(%s)" % (s, severity)
 
 def log_time():
     """Return a simple time string without spaces suitable for logging
     """
     return ("%4.4d-%2.2d-%2.2dT%2.2d:%2.2d:%2.2d"
-            % time.localtime()[:6])
+            % time.gmtime(time.time())[:6])
 
 def _set_log_dest(dest):
     global _log_dest
     _log_dest = dest
 
 _log_dest = None
-_stupid_severity = None
-_no_stupid_log = []
 
 class stupid_log_write:
 
@@ -87,8 +87,8 @@
         if error:
             try:
                 lines = format_exception(error[0], error[1], error[2],
-                                         limit=100)
-                print >> _log_dest, ''.join(lines)
+                                         trailer="\n", limit=100)
+                print >> _log_dest, lines
             except:
                 print >> _log_dest, "%s: %s" % error[:2]
         _log_dest.flush()


=== Zope3/lib/python/zLOG/__init__.py 1.5 => 1.6 ===
 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
 # 
 ##############################################################################
-
 """General logging facility
 
 This module attempts to provide a simple programming API for logging
@@ -25,7 +24,8 @@
 programs will replace this method with a method more suited to their needs.
 
 The module provides a register_subsystem method that does nothing, but
-provides a hook that logging management systems could use to collect information about subsystems being used.
+provides a hook that logging management systems could use to collect
+information about subsystems being used.
 
 The module defines several standard severities:
 
@@ -85,8 +85,8 @@
   - Ignores errors that have a severity < 0 by default. This
     can be overridden with the environment variable STUPID_LOG_SEVERITY
 
+$Id$
 """
-__version__='$Revision$'[11:-2]
 
 from MinimalLogger import log_write, log_time, severity_string, \
      _set_log_dest
@@ -142,4 +142,4 @@
 
 # Most apps interested in logging only want the names below.
 __all__ = ['LOG', 'TRACE', 'DEBUG', 'BLATHER', 'INFO', 'PROBLEM',
-           'WARNING', 'ERROR', 'PANIC', 'log_time']
+           'WARNING', 'ERROR', 'PANIC',]