Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use structured debug logging, and wrap JSON payloads in repr() #606

Merged
merged 2 commits into from
Feb 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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