[Zope-Checkins] CVS: ZODB3/zLOG - MinimalLogger.py:1.15

Guido van Rossum guido@python.org
Sat, 14 Sep 2002 15:25:12 -0400


Update of /cvs-repository/ZODB3/zLOG
In directory cvs.zope.org:/tmp/cvs-serv10417

Modified Files:
	MinimalLogger.py 
Log Message:
Don't shoot me.  I got tired of reading long log lines in an 80-char
wide xterm or emacs window.  So now, when using Python 2.3 or later,
the textwrap module is used to wrap the message line, indenting
subsequent lines past the timestamp.  Details and tracebacks are left
alone.


=== ZODB3/zLOG/MinimalLogger.py 1.14 => 1.15 ===
--- ZODB3/zLOG/MinimalLogger.py:1.14	Thu Sep 12 14:52:07 2002
+++ ZODB3/zLOG/MinimalLogger.py	Sat Sep 14 15:25:11 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,9 +80,13 @@
     def log(self, subsystem, severity, summary, detail, error):
         if _log_dest is None or severity < _log_level:
             return
-        buf = ["------",
-               "%s %s %s %s" %
-               (log_time(), severity_string(severity), subsystem, summary)]
+        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.append(str(detail))