[Zope3-checkins] CVS: Zope3/lib/python/ZEO/zrpc - connection.py:1.8
Guido van Rossum
guido@python.org
Thu, 19 Dec 2002 12:43:19 -0500
Update of /cvs-repository/Zope3/lib/python/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv4427
Modified Files:
connection.py
Log Message:
In preparation for more logging changes, port rev. 1.38.2.2 from the
ZODB 3.1 release branch:
Replace global log function with log method.
The log method includes the address of the other end of the
connection.
=== Zope3/lib/python/ZEO/zrpc/connection.py 1.7 => 1.8 ===
--- Zope3/lib/python/ZEO/zrpc/connection.py:1.7 Fri Nov 22 16:24:53 2002
+++ Zope3/lib/python/ZEO/zrpc/connection.py Thu Dec 19 12:43:19 2002
@@ -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