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

Guido van Rossum guido@python.org
Thu, 12 Sep 2002 14:52:08 -0400


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

Modified Files:
	MinimalLogger.py 
Log Message:
Change log() to cause exactly one write() call to _log_dest.  This
should fix the problem that messages from different processes or
threads could be intermingled.  The code was rewritten to build up the
lines of the error message in a list which is joined by "\n"
characters at the end.


=== ZODB3/zLOG/MinimalLogger.py 1.13 => 1.14 ===
--- ZODB3/zLOG/MinimalLogger.py:1.13	Fri Aug 16 16:28:45 2002
+++ ZODB3/zLOG/MinimalLogger.py	Thu Sep 12 14:52:07 2002
@@ -75,24 +75,24 @@
     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)]
 
         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()