mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
pyln: Pretty print RPC calls in the testing framework
We are printing `repr(obj)` which is not pretty-printed, hard to read, and can't even be copied and inspected to JSON tools. We now print the JSONified and indented calls and responses for easier debugging based on solely the logs (useful for CI!). Changelog-Added: pyln-testing: The RPC client will now pretty-print requests and responses to facilitate log-based debugging.
This commit is contained in:
parent
3ff82216c5
commit
ea67710e01
@ -592,6 +592,30 @@ class LightningD(TailableProc):
|
||||
return self.proc.returncode
|
||||
|
||||
|
||||
class PrettyPrintingLightningRpc(LightningRpc):
|
||||
"""A version of the LightningRpc that pretty-prints calls and results.
|
||||
|
||||
Useful when debugging based on logs, and less painful to the
|
||||
eyes. It has some overhead since we re-serialize the request and
|
||||
result to json in order to pretty print it.
|
||||
|
||||
"""
|
||||
|
||||
def call(self, method, payload=None):
|
||||
id = self.next_id
|
||||
self.logger.debug(json.dumps({
|
||||
"id": id,
|
||||
"method": method,
|
||||
"params": payload
|
||||
}, indent=2))
|
||||
res = LightningRpc.call(self, method, payload)
|
||||
self.logger.debug(json.dumps({
|
||||
"id": id,
|
||||
"result": res
|
||||
}, indent=2))
|
||||
return res
|
||||
|
||||
|
||||
class LightningNode(object):
|
||||
def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
|
||||
may_reconnect=False, allow_broken_log=False,
|
||||
@ -609,7 +633,7 @@ class LightningNode(object):
|
||||
self.rc = 0
|
||||
|
||||
socket_path = os.path.join(lightning_dir, TEST_NETWORK, "lightning-rpc").format(node_id)
|
||||
self.rpc = LightningRpc(socket_path, self.executor)
|
||||
self.rpc = PrettyPrintingLightningRpc(socket_path, self.executor)
|
||||
|
||||
self.daemon = LightningD(
|
||||
lightning_dir, bitcoindproxy=bitcoind.get_proxy(),
|
||||
|
Loading…
Reference in New Issue
Block a user