Skip to content

Add AnyLogger type (Logger | LoggerAdapter alias)Β #126093

@Avihais12344

Description

@Avihais12344

Feature or enhancement

Proposal:

AnyLogger: TypeAlias = Logger | LoggerAdapter

According to the docs, LoggerAdapter should look mostly like Logger. So it would be really nice to have a type that can be used for both Logger and LoggerAdapter.

I would need it when I want to hold a logger instance, but I don't really care if it's Logger or LoggerAdapter.
So I want to support both options.

It may sound like an antipattern, according to the docs, but using LoggerAdapter is the recommended way of passing contextual info (according to the docs).

Even when using contextvars for holding the logger, a AnyLogger type would be handy indeed.

I am willing to submit a PR fixing this issue, like I tried to do before:
#126057

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

#126057

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions