[Zope-Checkins] CVS: ZODB3/ZEO/zrpc - connection.py:1.38.2.1.4.1

Jeremy Hylton jeremy@zope.com
Tue, 17 Dec 2002 16:36:29 -0500


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

Modified Files:
      Tag: ZODB3-fast-restart-branch
	connection.py 
Log Message:
Replace global log function with log method.

The log method includes the address of the other end of the
connection.


=== ZODB3/ZEO/zrpc/connection.py 1.38.2.1 => 1.38.2.1.4.1 ===
--- ZODB3/ZEO/zrpc/connection.py:1.38.2.1	Tue Nov 12 15:18:09 2002
+++ ZODB3/ZEO/zrpc/connection.py	Tue Dec 17 16:36:29 2002
@@ -21,7 +21,7 @@
 import ThreadedAsync
 from ZEO.zrpc import smac
 from ZEO.zrpc.error import ZRPCError, DisconnectedError
-from ZEO.zrpc.log import log, short_repr
+from ZEO.zrpc.log import short_repr
 from ZEO.zrpc.marshal import Marshaller
 from ZEO.zrpc.trigger import trigger
 import zLOG
@@ -122,6 +122,10 @@
         self.marshal = Marshaller()
         self.closed = 0
         self.msgid = 0
+        if isinstance(addr, types.TupleType):
+            self.log_label = "zrpc-conn:%s:%d" % addr
+        else:
+            self.log_label = "zrpc-conn:%s" % addr
         self.__super_init(sock, addr)
         # A Connection either uses asyncore directly or relies on an
         # asyncore mainloop running in a separate thread.  If
@@ -147,6 +151,9 @@
 
     __str__ = __repr__ # Defeat asyncore's dreaded __getattr__
 
+    def log(self, message, level=zLOG.BLATHER, error=None):
+        zLOG.LOG(self.log_label, level, message, error=error)
+
     def close(self):
         if self.closed:
             return
@@ -182,8 +189,8 @@
         if message == self.protocol_version:
             self.message_input = self._message_input
         else:
-            log("recv_handshake: bad handshake %s" % short_repr(message),
-                level=zLOG.ERROR)
+            self.log("recv_handshake: bad handshake %s" % short_repr(message),
+                     level=zLOG.ERROR)
         # otherwise do something else...
 
     def message_input(self, message):
@@ -195,9 +202,9 @@
         msgid, flags, name, args = self.marshal.decode(message)
 
         if __debug__:
-            log("recv msg: %s, %s, %s, %s" % (msgid, flags, name,
-                                              short_repr(args)),
-                level=zLOG.TRACE)
+            self.log("recv msg: %s, %s, %s, %s" % (msgid, flags, name,
+                                                   short_repr(args)),
+                     level=zLOG.TRACE)
         if name == REPLY:
             self.handle_reply(msgid, flags, args)
         else:
@@ -205,8 +212,8 @@
 
     def handle_reply(self, msgid, flags, args):
         if __debug__:
-            log("recv reply: %s, %s, %s" % (msgid, flags, short_repr(args)),
-                level=zLOG.DEBUG)
+            self.log("recv reply: %s, %s, %s"
+                     % (msgid, flags, short_repr(args)), level=zLOG.DEBUG)
         self.replies_cond.acquire()
         try:
             self.replies[msgid] = flags, args
@@ -219,7 +226,8 @@
             msg = "Invalid method name: %s on %s" % (name, repr(self.obj))
             raise ZRPCError(msg)
         if __debug__:
-            log("calling %s%s" % (name, short_repr(args)), level=zLOG.BLATHER)
+            self.log("calling %s%s" % (name, short_repr(args)),
+                     level=zLOG.BLATHER)
 
         meth = getattr(self.obj, name)
         try:
@@ -228,8 +236,8 @@
             raise
         except Exception, msg:
             error = sys.exc_info()
-            log("%s() raised exception: %s" % (name, msg), zLOG.INFO,
-                error=error)
+            self.log("%s() raised exception: %s" % (name, msg), zLOG.INFO,
+                     error=error)
             error = error[:2]
             return self.return_error(msgid, flags, *error)
 
@@ -239,7 +247,7 @@
                                 (name, short_repr(ret)))
         else:
             if __debug__:
-                log("%s returns %s" % (name, short_repr(ret)), zLOG.DEBUG)
+                self.log("%s returns %s" % (name, short_repr(ret)), zLOG.DEBUG)
             if isinstance(ret, Delay):
                 ret.set_sender(msgid, self.send_reply, self.return_error)
             else:
@@ -252,7 +260,7 @@
         self.close()
 
     def log_error(self, msg="No error message supplied"):
-        log(msg, zLOG.ERROR, error=sys.exc_info())
+        self.log(msg, zLOG.ERROR, error=sys.exc_info())
 
     def check_method(self, name):
         # XXX Is this sufficient "security" for now?
@@ -304,8 +312,8 @@
         finally:
             self.msgid_lock.release()
         if __debug__:
-            log("send msg: %d, %d, %s, ..." % (msgid, flags, method),
-                zLOG.TRACE)
+            self.log("send msg: %d, %d, %s, ..." % (msgid, flags, method),
+                     zLOG.TRACE)
         buf = self.marshal.encode(msgid, flags, method, args)
         self.message_output(buf)
         return msgid
@@ -360,8 +368,8 @@
     def wait(self, msgid):
         """Invoke asyncore mainloop and wait for reply."""
         if __debug__:
-            log("wait(%d), async=%d" % (msgid, self.is_async()),
-                level=zLOG.TRACE)
+            self.log("wait(%d), async=%d" % (msgid, self.is_async()),
+                     level=zLOG.TRACE)
         if self.is_async():
             self._pull_trigger()
 
@@ -378,8 +386,8 @@
                 if reply is not None:
                     del self.replies[msgid]
                     if __debug__:
-                        log("wait(%d): reply=%s" % (msgid, short_repr(reply)),
-                            level=zLOG.DEBUG)
+                        self.log("wait(%d): reply=%s" %
+                                 (msgid, short_repr(reply)), level=zLOG.DEBUG)
                     return reply
                 if self.is_async():
                     self.replies_cond.wait(10.0)
@@ -388,14 +396,14 @@
                     try:
                         try:
                             if __debug__:
-                                log("wait(%d): asyncore.poll(%s)" %
-                                    (msgid, delay), level=zLOG.TRACE)
+                                self.log("wait(%d): asyncore.poll(%s)" %
+                                         (msgid, delay), level=zLOG.TRACE)
                             asyncore.poll(delay, self._map)
                             if delay < 1.0:
                                 delay += delay
                         except select.error, err:
-                            log("Closing.  asyncore.poll() raised %s." % err,
-                                level=zLOG.BLATHER)
+                            self.log("Closing.  asyncore.poll() raised %s."
+                                     % err, level=zLOG.BLATHER)
                             self.close()
                     finally:
                         self.replies_cond.acquire()
@@ -405,7 +413,7 @@
     def poll(self):
         """Invoke asyncore mainloop to get pending message out."""
         if __debug__:
-            log("poll(), async=%d" % self.is_async(), level=zLOG.TRACE)
+            self.log("poll(), async=%d" % self.is_async(), level=zLOG.TRACE)
         if self.is_async():
             self._pull_trigger()
         else:
@@ -414,7 +422,7 @@
     def pending(self):
         """Invoke mainloop until any pending messages are handled."""
         if __debug__:
-            log("pending(), async=%d" % self.is_async(), level=zLOG.TRACE)
+            self.log("pending(), async=%d" % self.is_async(), level=zLOG.TRACE)
         if self.is_async():
             return
         # Inline the asyncore poll() function to know whether any input