Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aminalaee opened this issue Mar 21, 2023 · 3 comments · Fixed by #102875
Closed

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

aminalaee opened this issue Mar 21, 2023 · 3 comments · Fixed by #102875
Labels
docs Documentation in the Doc dir

Comments

@aminalaee
Copy link
Contributor

aminalaee commented Mar 21, 2023

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

@aminalaee
Copy link
Contributor Author

cc @AlexWaygood

@aminalaee aminalaee 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 Mar 21, 2023
@AlexWaygood AlexWaygood moved this to In Progress in Logging issues 🪵 Mar 21, 2023
@arhadthedev
Copy link
Member

@vsajip (as a logging expert)

@github-project-automation github-project-automation bot moved this from In Progress to Done in Logging issues 🪵 Mar 24, 2023
AlexWaygood added a commit that referenced this issue Mar 24, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 24, 2023
… parameter (pythonGH-102875)

(cherry picked from commit f2e5a6e)

Co-authored-by: Amin Alaee <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Mar 24, 2023
… parameter (pythonGH-102875)

(cherry picked from commit f2e5a6e)

Co-authored-by: Amin Alaee <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
miss-islington added a commit that referenced this issue Mar 24, 2023
…eter (GH-102875)

(cherry picked from commit f2e5a6e)

Co-authored-by: Amin Alaee <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
miss-islington added a commit that referenced this issue Mar 24, 2023
…eter (GH-102875)

(cherry picked from commit f2e5a6e)

Co-authored-by: Amin Alaee <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
@AlexWaygood
Copy link
Member

Thanks @aminalaee!

Fidget-Spinner pushed a commit to Fidget-Spinner/cpython that referenced this issue Mar 27, 2023
warsaw pushed a commit to warsaw/cpython that referenced this issue Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Development

Successfully merging a pull request may close this issue.

3 participants