[Zodb-checkins] CVS: Zope3/lib/python/ZEO - ClientCache.py:1.29

Guido van Rossum guido@python.org
Thu, 19 Dec 2002 14:33:53 -0500


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

Modified Files:
	ClientCache.py 
Log Message:
Convert to using the logging module, using the sublogger machinery.


=== Zope3/lib/python/ZEO/ClientCache.py 1.28 => 1.29 ===
--- Zope3/lib/python/ZEO/ClientCache.py:1.28	Mon Nov 25 14:54:50 2002
+++ Zope3/lib/python/ZEO/ClientCache.py	Thu Dec 19 14:33:52 2002
@@ -105,10 +105,10 @@
 import tempfile
 from struct import pack, unpack
 from thread import allocate_lock
+import logging
 
 from ZODB.utils import u64
 
-import zLOG
 from ZEO.ICache import ICache
 
 magic='ZEC0'
@@ -127,6 +127,10 @@
         self._storage = storage
         self._limit = size / 2
 
+        # Create a logger specific for this client cache
+        logger = logging.getLogger("ZEC.%s" % storage)
+        self.log = logger.warn
+
         # Allocate locks:
         L = allocate_lock()
         self._acquire = L.acquire
@@ -182,8 +186,7 @@
             f[0].write(magic)
             current = 0
 
-        self.log("%s: storage=%r, size=%r; file[%r]=%r" %
-                 (self.__class__.__name__, storage, size, current, p[current]))
+        self.log("size=%r; file[%r]=%r", size, current, p[current])
 
         self._current = current
         self._setup_trace()
@@ -240,14 +243,14 @@
             h = f.read(27)
             if len(h) != 27:
                 self.log("invalidate: short record for oid %16x "
-                         "at position %d in cache file %d"
-                         % (u64(oid), ap, p < 0))
+                         "at position %d in cache file %d",
+                         u64(oid), ap, p < 0)
                 del self._index[oid]
                 return None
             if h[:8] != oid:
                 self.log("invalidate: oid mismatch: expected %16x read %16x "
-                         "at position %d in cache file %d"
-                         % (u64(oid), u64(h[:8]), ap, p < 0))
+                         "at position %d in cache file %d",
+                         u64(oid), u64(h[:8]), ap, p < 0)
                 del self._index[oid]
                 return None
             f.seek(ap+8) # Switch from reading to writing
@@ -281,8 +284,8 @@
                 tlen = -1
             if tlen <= 0 or vlen < 0 or dlen < 0 or vlen+dlen > tlen:
                 self.log("load: bad record for oid %16x "
-                         "at position %d in cache file %d"
-                         % (u64(oid), ap, p < 0))
+                         "at position %d in cache file %d",
+                         u64(oid), ap, p < 0)
                 del self._index[oid]
                 return None
 
@@ -452,8 +455,8 @@
                 tlen = -1
             if tlen <= 0 or vlen < 0 or dlen < 0 or vlen+dlen > tlen:
                 self.log("modifiedInVersion: bad record for oid %16x "
-                         "at position %d in cache file %d"
-                         % (u64(oid), ap, p < 0))
+                         "at position %d in cache file %d",
+                         u64(oid), ap, p < 0)
                 del self._index[oid]
                 return None
 
@@ -480,7 +483,7 @@
                 current = not self._current
                 self._current = current
                 self._trace(0x70)
-                self.log("flipping cache files.  new current = %d" % current)
+                self.log("flipping cache files.  new current = %d", current)
                 # Delete the half of the index that's no longer valid
                 index = self._index
                 for oid in index.keys():
@@ -562,9 +565,9 @@
                 self._trace(0x00)
             except IOError, msg:
                 self._tracefile = None
-                self.log("cannot write tracefile %s (%s)" % (tfn, msg))
+                self.log("cannot write tracefile %s (%s)", tfn, msg)
             else:
-                self.log("opened tracefile %s" % tfn)
+                self.log("opened tracefile %s", tfn)
         if self._tracefile is None:
             def notrace(*args):
                 pass
@@ -663,15 +666,12 @@
             pass
 
         if count:
-            self.log("read_index: cache file %d has %d records and %d bytes"
-                     % (fileindex, count, pos))
+            self.log("read_index: cache file %d has %d records and %d bytes",
+                     fileindex, count, pos)
 
         return pos
 
     def rilog(self, msg, pos, fileindex):
-        # Helper to log messages from read_index
-        self.log("read_index: %s at position %d in cache file %d"
-                 % (msg, pos, fileindex))
-
-    def log(self, msg, level=zLOG.INFO):
-        zLOG.LOG("ZEC:%s" % self._storage, level, msg)
+        # Helper to log certain messages from read_index
+        self.log("read_index: %s at position %d in cache file %d",
+                 msg, pos, fileindex)