Skip to content

logging module LogRecord can accept non-str msg but it's not documented #102873

Closed
@aminalaee

Description

@aminalaee

Documentation

In the documentation of the logging LogRecord it's mentioned that it accepts msg as str argument:
https://docs.python.org/3/library/logging.html#logging.LogRecord

But just below that it explains that in getMessage:

Returns the message for this LogRecord instance after merging any user-supplied arguments with the message. If the user-supplied message argument to the logging call is not a string, str() is called on it to convert it to a string. This allows use of user-defined classes as messages, whose str method can return the actual format string to be used.

So non-str messages are allowed, and also in LogRecord attributes it's mentioned that non-str messages work and are accepted:
https://docs.python.org/3/library/logging.html#logrecord-attributes

Initially started the discussion in python/typeshed#9914

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions