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): ...@@ -285,8 +285,7 @@ class Connection(BaseConnection):
Process a pending packet. Process a pending packet.
""" """
packet = self._dequeue() packet = self._dequeue()
logging.debug('#0x%08x %-30s from %s (%s:%d)', packet.getId(), self.logPacket('from', packet)
packet.getType(), dump(self.uuid), *self.getAddress())
self.handler.packetReceived(self, packet) self.handler.packetReceived(self, packet)
def pending(self): def pending(self):
...@@ -347,13 +346,25 @@ class Connection(BaseConnection): ...@@ -347,13 +346,25 @@ class Connection(BaseConnection):
self.handler.connectionClosed(self) self.handler.connectionClosed(self)
raise 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): def _addPacket(self, packet):
"""Add a packet into the write buffer.""" """Add a packet into the write buffer."""
if self.connector is None: if self.connector is None:
return return
logging.debug('#0x%08x %-30s to %s (%s:%d)', packet.getId(), self.logPacket(' to ', packet)
packet.getType(), dump(self.uuid), *self.getAddress())
try: try:
self.write_buf += packet.encode() self.write_buf += packet.encode()
except PacketMalformedError, m: 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