From 192cde605e20d70b65e4e2a5e260e513f2a11350 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Fri, 26 Apr 2024 15:28:54 +0200 Subject: [PATCH] frappy.client.SecopClient: add the option to use no logging at all using a dummy NullLogger Change-Id: I1f12c7307d3d8e37243488b8a11c6abcf087af86 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/33582 Tested-by: Jenkins Automated Tests Reviewed-by: Markus Zolliker --- frappy/client/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frappy/client/__init__.py b/frappy/client/__init__.py index bacb7c7..e5e437a 100644 --- a/frappy/client/__init__.py +++ b/frappy/client/__init__.py @@ -68,6 +68,10 @@ class Logger: error = exception = warning = critical = info +class NullLogger(Logger): + error = exception = warning = critical = info = Logger.noop + + class CallbackObject: """abstract definition for a target object for callbacks @@ -290,6 +294,13 @@ class SecopClient(ProxyClient): _max_error_count = 10 def __init__(self, uri, log=Logger): + """initialize SecopClient + + :param uri: the uri to connect to + :param log: a logger. + when not given, the print command is used for messages with at least info level. + when None, nothing is logged at all + """ super().__init__() # maps expected replies to [request, Event, is_error, result] until a response came # there can only be one entry per thread calling 'request' @@ -297,7 +308,7 @@ class SecopClient(ProxyClient): self.io = None self.txq = queue.Queue(30) # queue for tx requests self.pending = queue.Queue(30) # requests with colliding action + ident - self.log = log + self.log = log or NullLogger self.uri = uri self.nodename = uri self._lock = RLock()