[Zodb-checkins] CVS: Zope/lib/python/zLOG - MinimalLogger.py:1.13.4.1

Chris McDonough chrism@zope.com
Mon, 16 Sep 2002 02:00:56 -0400


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

Modified Files:
      Tag: chrism-install-branch
	MinimalLogger.py 
Log Message:
Merging with HEAD.


=== Zope/lib/python/zLOG/MinimalLogger.py 1.13 => 1.13.4.1 ===
--- Zope/lib/python/zLOG/MinimalLogger.py:1.13	Fri Aug 16 16:28:45 2002
+++ Zope/lib/python/zLOG/MinimalLogger.py	Mon Sep 16 02:00:55 2002
@@ -15,6 +15,11 @@
 
 import os, sys, time
 
+try:
+    import textwrap
+except ImportError:
+    textwrap = None
+
 from FormatException import format_exception
 
 def severity_string(severity, mapping={
@@ -75,24 +80,28 @@
     def log(self, subsystem, severity, summary, detail, error):
         if _log_dest is None or severity < _log_level:
             return
+        buf = ["------"]
+        line = ("%s %s %s %s" %
+                (log_time(), severity_string(severity), subsystem, summary))
+        if not textwrap or len(line) < 80:
+            buf.append(line)
+        else:
+            buf.extend(textwrap.wrap(line, subsequent_indent=" "*20))
 
         if detail:
-            buf = ("------\n"
-                   "%s %s %s %s\n%s" % (log_time(), severity_string(severity),
-                                        subsystem, summary, detail))
-        else:
-            buf = ("------\n"
-                   "%s %s %s %s" % (log_time(), severity_string(severity),
-                                    subsystem, summary))
-        print >> _log_dest, buf
+            buf.append(str(detail))
 
         if error:
             try:
                 lines = format_exception(error[0], error[1], error[2],
                                          limit=100)
-                print >> _log_dest, ''.join(lines)
-            except:
-                print >> _log_dest, "%s: %s" % error[:2]
+                buf.append(''.join(lines))
+            except '':
+                buf.append("%s: %s" % error[:2])
+
+        buf.append("") # Cause a final \n to be appended
+
+        _log_dest.write("\n".join(buf))
         _log_dest.flush()