Skip to content

Commit

Permalink
Merge pull request #606 from meejah/599-frame-logging
Browse files Browse the repository at this point in the history
use structured debug logging, and wrap JSON payloads in repr()
  • Loading branch information
Tobias Oberstein committed Feb 26, 2016
2 parents 84ae393 + b69b4e7 commit a7c3ca3
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions autobahn/websocket/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,33 +1130,35 @@ def logRxFrame(self, frameHeader, payload):
but only when self.logFrames == True.
"""
data = b''.join(payload)
info = (self.peer,
frameHeader.fin,
frameHeader.rsv,
frameHeader.opcode,
binascii.b2a_hex(frameHeader.mask) if frameHeader.mask else "-",
frameHeader.length,
data if frameHeader.opcode == 1 else binascii.b2a_hex(data))

self.log.debug("RX Frame from %s : fin = %s, rsv = %s, opcode = %s, mask = %s, length = %s, payload = %s" % info)
self.log.debug(
"RX Frame from {peer} : fin = {fin}, rsv = {rsv}, opcode = {opcode}, mask = {mask}, length = {length}, payload = {payload}",
peer=self.peer,
fin=frameHeader.fin,
rsv=frameHeader.rsv,
opcode=frameHeader.opcode,
mask=binascii.b2a_hex(frameHeader.mask) if frameHeader.mask else "-",
length=frameHeader.length,
payload=repr(data) if frameHeader.opcode == 1 else binascii.b2a_hex(data),
)

def logTxFrame(self, frameHeader, payload, repeatLength, chopsize, sync):
"""
Hook fired right after WebSocket frame has been encoded and sent, but
only when self.logFrames == True.
"""
info = (self.peer,
frameHeader.fin,
frameHeader.rsv,
frameHeader.opcode,
binascii.b2a_hex(frameHeader.mask) if frameHeader.mask else "-",
frameHeader.length,
repeatLength,
chopsize,
sync,
payload if frameHeader.opcode == 1 else binascii.b2a_hex(payload))

self.log.debug("TX Frame to %s : fin = %s, rsv = %s, opcode = %s, mask = %s, length = %s, repeat_length = %s, chopsize = %s, sync = %s, payload = %s" % info)
self.log.debug(
"TX Frame to {peer} : fin = {fin}, rsv = {rsv}, opcode = {opcode}, mask = {mask}, length = {length}, repeat_length = {repeat_length}, chopsize = {chopsize}, sync = {sync}, payload = {payload}",
peer=self.peer,
fin=frameHeader.fin,
rsv=frameHeader.rsv,
opcode=frameHeader.opcode,
mask=binascii.b2a_hex(frameHeader.mask) if frameHeader.mask else "-",
length=frameHeader.length,
repeat_length=repeatLength,
chopsize=chopsize,
sync=sync,
payload=repr(payload) if frameHeader.opcode == 1 else binascii.b2a_hex(payload),
)

def _dataReceived(self, data):
"""
Expand Down

0 comments on commit a7c3ca3

Please sign in to comment.