mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
pylightning: Added explicit logger to log to
Signed-off-by: Christian Decker <decker.christian@gmail.com> Co-authored-by: Guido Dassori @gdassori
This commit is contained in:
parent
33b25b6a9b
commit
ed2fee8977
1 changed files with 4 additions and 5 deletions
|
@ -1,15 +1,14 @@
|
||||||
from concurrent import futures
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
|
||||||
class UnixDomainSocketRpc(object):
|
class UnixDomainSocketRpc(object):
|
||||||
def __init__(self, socket_path, executor=None):
|
def __init__(self, socket_path, executor=None, logger=logging):
|
||||||
self.socket_path = socket_path
|
self.socket_path = socket_path
|
||||||
self.decoder = json.JSONDecoder()
|
self.decoder = json.JSONDecoder()
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _writeobj(sock, obj):
|
def _writeobj(sock, obj):
|
||||||
|
@ -45,7 +44,7 @@ class UnixDomainSocketRpc(object):
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
def _call(self, method, args=None):
|
def _call(self, method, args=None):
|
||||||
logging.debug("Calling %s with arguments %r", method, args)
|
self.logger.debug("Calling %s with payload %r", method, payload)
|
||||||
|
|
||||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
sock.connect(self.socket_path)
|
sock.connect(self.socket_path)
|
||||||
|
@ -57,12 +56,12 @@ class UnixDomainSocketRpc(object):
|
||||||
resp = self._readobj(sock)
|
resp = self._readobj(sock)
|
||||||
sock.close()
|
sock.close()
|
||||||
|
|
||||||
logging.debug("Received response for %s call: %r", method, resp)
|
|
||||||
if 'error' in resp:
|
if 'error' in resp:
|
||||||
raise ValueError("RPC call failed: {}".format(resp['error']))
|
raise ValueError("RPC call failed: {}".format(resp['error']))
|
||||||
elif 'result' not in resp:
|
elif 'result' not in resp:
|
||||||
raise ValueError("Malformed response, 'result' missing.")
|
raise ValueError("Malformed response, 'result' missing.")
|
||||||
return resp['result']
|
return resp['result']
|
||||||
|
self.logger.debug("Received response for %s call: %r", method, resp)
|
||||||
|
|
||||||
|
|
||||||
class LightningRpc(UnixDomainSocketRpc):
|
class LightningRpc(UnixDomainSocketRpc):
|
||||||
|
|
Loading…
Add table
Reference in a new issue