bastimeyer · GitHub

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's NONE log level gets interpreted in Python's logging module.

Each logger instance (subclasses of logging.Logger or streamlink.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 to logging.UNSET (which is the default and its value is 0), then it continues with its parent logger instance until it reaches logging.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

    def getEffectiveLevel(self):
        """
        Get the effective level for this logger.
        Loop through this logger and its parents in the logger hierarchy,
        looking for a non-zero logging level. Return the first one found.
        """
        logger = self
        while logger:
            if logger.level:
                return logger.level
            logger = logger.parent
        return NOTSET

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 to NONE (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 to sys.maxsize, so that getEffectiveLevel() doesn't continue with the next parent logger if one of the logger instance's level is set to NONE. 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)

$ streamlink youtube.com/c/LudwigAhgren -j
{
  "error": "No playable streams found on this URL: youtube.com/c/LudwigAhgren"
}

Read the original on github.com ↗