Avoid printing an ERROR log on failed connection#76
Open
pniedzielski wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_pythonlog 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: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.