From eb8d2a3896c214113d91ab28e3e0f7cc5e56941b Mon Sep 17 00:00:00 2001 From: "Patrick M. Niedzielski" Date: Sun, 7 Jun 2026 21:21:31 +0000 Subject: [PATCH] Avoid printing an `ERROR` log on failed connection If a client attempts to connect to OBS, and OBS is not running, this library will print out a full traceback of an exception as an ERROR. This is bad behavior: in the case of a daemon-like program that automatically connects or reconnects to OBS, this will spew multiline ERROR traceback logs for the routine case that OBS has not started up yet, which can easily and correctly be handled by the program handling the re-raised exception itself. Furthermore, it is hard to correctly suppress this log outside of this library: the program needs to add a handler that filters out `obsws_python` log records only while attempting to connect, and only on the thread that is attempting to connect, lest we fail to log other ERRORs happening on different obsws connections: ``` class _SuppressObsLogsHandler(logging.Handler): """Temporarily discard log records from obsws_python on the creating thread.""" def __init__(self): super().__init__(level=logging.DEBUG) self._thread_id = threading.get_ident() def filter(self, record): if ( threading.get_ident() == self._thread_id and record.name.startswith("obsws_python") ): return False return True def emit(self, record): # Forward to lastResort for records we aren't suppressing, since # our presence on root already prevents lastResort from firing. if logging.lastResort and record.levelno >= logging.lastResort.level: logging.lastResort.handle(record) ``` This patch changes the logging level for failed connections from ERROR to DEBUG. This allows a program using this library to suppress DEBUG logging on the library much more easily than above while still being able to log an ERROR themselves if the failed connection truly is erroneous. --- obsws_python/baseclient.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obsws_python/baseclient.py b/obsws_python/baseclient.py index d3e20b2..ce282da 100644 --- a/obsws_python/baseclient.py +++ b/obsws_python/baseclient.py @@ -44,7 +44,7 @@ def __init__(self, **kwargs): self.logger.error(f"{type(e).__name__}: {e}") raise except (ConnectionRefusedError, TimeoutError, WebSocketTimeoutException) as e: - self.logger.exception(f"{type(e).__name__}: {e}") + self.logger.debug(f"{type(e).__name__}: {e}") raise def _conn_from_toml(self) -> dict: