[Zodb-checkins] CVS: ZODB3/ZEO/zrpc - log.py:1.6

Guido van Rossum guido@python.org
Sat, 28 Sep 2002 23:10:03 -0400


Update of /cvs-repository/ZODB3/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv26024

Modified Files:
	log.py 
Log Message:
Two unrelated niceties:

1) An option to add the thread name to the label.  This is very handy
   during heavy debugging, but also very expensive (two extra function
   calls and some string formatting), so it is off by default; you
   have to edit this file to enable it.

2) In short_repr(), for strings, show the string quote after the three
   trailing dots.


=== ZODB3/ZEO/zrpc/log.py 1.5 => 1.6 ===
--- ZODB3/ZEO/zrpc/log.py:1.5	Mon Sep 16 23:40:34 2002
+++ ZODB3/ZEO/zrpc/log.py	Sat Sep 28 23:10:03 2002
@@ -14,6 +14,9 @@
 import os
 import types
 import zLOG
+import threading
+
+LOG_THREAD_ID = 0 # Set this to 1 during heavy debugging
 
 _label = "zrpc:%s" % os.getpid()
 
@@ -22,7 +25,10 @@
     _label = "zrpc:%s" % os.getpid()
 
 def log(message, level=zLOG.BLATHER, label=None, error=None):
-    zLOG.LOG(label or _label, level, message, error=error)
+    label = label or _label
+    if LOG_THREAD_ID:
+        label = "%s:%s" % (label, threading.currentThread().getName())
+    zLOG.LOG(label, level, message, error=error)
 
 REPR_LIMIT = 40
 
@@ -40,7 +46,13 @@
     # module name in the pickle.
 
     if isinstance(obj, types.StringType):
-        r = `obj[:REPR_LIMIT]`
+        if len(obj) > REPR_LIMIT:
+            r = repr(obj[:REPR_LIMIT])
+        else:
+            r = repr(obj)
+        if len(r) > REPR_LIMIT:
+            r = r[:REPR_LIMIT-4] + '...' + r[-1]
+        return r
     elif isinstance(obj, types.TupleType):
         elts = []
         size = 0