logger: change NONE loglevel to sys.maxsize#4258
Merged
Merged
Conversation
- Change NONE from 0 to sys.maxsize: This fixes an issue with `logging.Logger.getEffectiveLevel()` which would otherwise choose `logging.root` as logger instance when Streamlink's loglevel was set to "none", whose default log level is set to "warning", so errors did still get logged. - Rearrange global scope vars - Add support for uppercase "TRACE" log level name - Add typings to baseConfig() - Add tests for log streams and child loggers
gravyboat
approved these changes
Dec 19, 2021
gravyboat
left a comment
Member
There was a problem hiding this comment.
Looks good to me @bastimeyer, good investigation in to the root cause. I'll leave this open today to see if others have any concerns, if not let's merge this in.
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Dec 20, 2021
Billy2011
added a commit
to Billy2011/streamlink-27
that referenced
this pull request
Dec 21, 2021
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.
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-urlor even--loglevel=none) is because of how Streamlink'sNONElog level gets interpreted in Python's logging module.Each logger instance (subclasses of
logging.Loggerorstreamlink.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.NONEvalue 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)