Thanks to visit codestin.com
Credit goes to github.com

Skip to content

logger: custom trace() log level has incorrect module name on Python 3.11 #4862

Description

@bastimeyer

Python 3.11 has changed how the call stack gets read when creating a new log record:
python/cpython@5ca6d74

This causes the log record's module name to be set to Streamlink's logger module where the custom trace() method is defined, which is incorrect.

Example:
https://github.com/streamlink/streamlink/actions/runs/3168863166/jobs/5160366442#step:5:285
#4861 (comment)

Is this worth of a Python but report, or do we need to change how the custom trace() method is defined?

Since there's no way to pass a custom call stack to the Logger._log() method, the stacklevel needs to be increased from 1 to 2 on py311 from what it looks like, so that it skips the logger module at the beginning of the call stack:

class StreamlinkLogger(_BaseLoggerClass):
    if sys.version_info < (3, 11):
        def trace(self, message, *args, **kws):
            if self.isEnabledFor(TRACE):
                self._log(TRACE, message, args, **kws)
    else:
        def trace(self, message, *args, **kws):
            if self.isEnabledFor(TRACE):
                kws["stacklevel"] = 2
                self._log(TRACE, message, args, **kws)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions