logger: change NONE loglevel to sys.maxsize #4258
Merged
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.
Resolves #4235
The reason why there are still log messages being written to stdout/stderr when any "silent" CLI argument is set (
--json
,--quiet
,--stream-url
or even--loglevel=none
) is because of how Streamlink'sNONE
log level gets interpreted in Python's logging module.Each logger instance (subclasses of
logging.Logger
orstreamlink.logger.StreamlinkLogger
) can optionally have their own log level. When a logger instance needs to check whether a certain message can be written to the output or not, it first tries to read its own log level value, and if it is set tologging.UNSET
(which is the default and its value is 0), then it continues with its parent logger instance until it reacheslogging.root
(RootLogger
). This RootLogger does have a default log level of 30, aka. "warning".https://github.com/python/cpython/blame/3.10/Lib/logging/__init__.py#L1926-L1927
logging.Logger.getEffectiveLevel()
:https://github.com/python/cpython/blame/3.10/Lib/logging/__init__.py#L1701-L1713
Since child loggers usually don't have their own log level set, the loggers like the one in the YouTube plugin for example look up the level of Streamlink's own root logger
streamlink.logger.root
. If the level of Streamlink's root logger however is set toNONE
(0), then the level of the global RootLogger will be used ("warning"), which means everything equal to or above "warning", like error log messages for example, will still be logged.The fix is to change the
streamlink.logger.NONE
value from 0 tosys.maxsize
, so thatgetEffectiveLevel()
doesn't continue with the next parent logger if one of the logger instance's level is set toNONE
. This has been broken since the reimplementation of the logger module in 2018.Please review carefully before merging, because I don't want to unintentionally break stuff.
The other changes are all optional. See the commit messages for details.
#4235 (comment)