Commit 2cd1a166 authored by Vincent Pelletier's avatar Vincent Pelletier

Factorise packet logging code.

Add a more detailed logging of ERROR packets (print error code and message).


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1098 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a3e44f99
......@@ -285,8 +285,7 @@ class Connection(BaseConnection):
Process a pending packet.
"""
packet = self._dequeue()
logging.debug('#0x%08x %-30s from %s (%s:%d)', packet.getId(),
packet.getType(), dump(self.uuid), *self.getAddress())
self.logPacket('from', packet)
self.handler.packetReceived(self, packet)
def pending(self):
......@@ -347,13 +346,25 @@ class Connection(BaseConnection):
self.handler.connectionClosed(self)
raise
def logPacket(self, direction, packet):
packet_type = packet.getType()
ip, port = self.getAddress()
if packet_type == protocol.ERROR:
code, message = packet.decode()
logging.debug('#0x%08x ERROR %-24s %s %s (%s:%d) %s',
packet.getId(), code, direction, dump(self.uuid),
ip, port, message)
else:
logging.debug('#0x%08x %-30s %s %s (%s:%d)', packet.getId(),
packet_type, direction, dump(self.uuid),
ip, port)
def _addPacket(self, packet):
"""Add a packet into the write buffer."""
if self.connector is None:
return
logging.debug('#0x%08x %-30s to %s (%s:%d)', packet.getId(),
packet.getType(), dump(self.uuid), *self.getAddress())
self.logPacket(' to ', packet)
try:
self.write_buf += packet.encode()
except PacketMalformedError, m:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment