mbr / tinyrpc

A compact, modular transport and protocol agnostic RPC library. Does jsonrpc v2.
https://tinyrpc.readthedocs.org
MIT License
156 stars 53 forks source link

Tracing JSON objects #23

Closed piedenis closed 7 years ago

piedenis commented 8 years ago

tinyrpc is very nice for abstracting RPC between a Python client and a Python server. It's great because I don't have to care about underlying JSON objects. However, I have to create now a JSON-RPC Python server for a JSON-RPC Java client. For debugging purpose, is it possible to trace the JSON objects received and emitted by tinyrpc? How can I do that?

lnoor commented 7 years ago

I propose to use a DEBUG logging level for that. Strike that, I added a property trace to RPCServer. When it is set to a callable after constructing RPCServer it will get called with three parameters:

So your trace code could look like:

def my_trace(direction, context, message):
    logger.debug('%s%s', direction, message)

server = RPCServer(transport, protocol, dispatcher)
server.trace = my_trace
server.serve_forever()