Skip to content

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

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

Activity

  1. added a commit that references this issue on Mar 21, 2023
  2. aminalaee commented on Mar 21, 2023

    @aminalaee
    ContributorAuthor
  3. changed the title [-]logging module LogRecord can accept non-str msg but it's not reflected[/-] [+]logging module LogRecord can accept non-str msg but it's not documented[/+] on Mar 21, 2023
  4. arhadthedev commented on Mar 22, 2023

    @arhadthedev
    Member

    @vsajip (as a logging expert)

  5. added a commit that references this issue on Mar 24, 2023
  6. added 4 commits that reference this issue on Mar 24, 2023
  7. AlexWaygood commented on Mar 24, 2023

    @AlexWaygood
    Member

    Thanks @aminalaee!

  8. added a commit that references this issue on Mar 27, 2023
  9. added a commit that references this issue on Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions