diff --git a/src/radical/utils/zmq/client.py b/src/radical/utils/zmq/client.py index 3e6e5532..c04ff3c5 100644 --- a/src/radical/utils/zmq/client.py +++ b/src/radical/utils/zmq/client.py @@ -8,7 +8,8 @@ from ..json_io import read_json from ..misc import as_string from ..serialize import to_msgpack, from_msgpack -from .utils import no_intr, sock_connect, LOG_ENABLED +from ..logger import Logger +from .utils import no_intr, sock_connect # ------------------------------------------------------------------------------ @@ -24,8 +25,9 @@ class Client(object): # -------------------------------------------------------------------------- # - def __init__(self, server: str = None, - url: str = None) -> None: + def __init__(self, server: str = None, + url: str = None, + log: Logger = None) -> None: if server: self._url = read_json('%s.cfg' % server)['addr'] @@ -36,8 +38,8 @@ def __init__(self, server: str = None, else: raise ValueError('need server name/cfg or Url') + self._log = log self._cb = None - self._ctx = zmq.Context() self._sock = self._ctx.socket(zmq.REQ) @@ -61,9 +63,14 @@ def url(self) -> str: # def request(self, cmd: str, *args: Any, **kwargs: Any) -> Any: - req = to_msgpack({'cmd' : cmd, - 'args' : args, - 'kwargs': kwargs}) + msg = {'cmd' : cmd, + 'args' : args, + 'kwargs': kwargs} + + if self._log: + self._log.debug('request: %s', msg) + + req = to_msgpack(msg) no_intr(self._sock.send, req)