-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Logger formatter class initialization state clarification #127805
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
Comments
@jlynchMicron I would like to work on this, I wanted to ask how necessary the proposed change to the setFormatter method is. Would allowing it to accept both formatter instances and classes have a significant impact on the usability or functionality of the logging module? The current behavior works if users follow the documentation, though it could be clearer. Is this change something that is critical to address, or would clarifying the documentation alone be sufficient? |
Hi @Uvi-12, I believe clarification in the documentation would totally be sufficient. The error message generated when using an un-initialized formatter class is not very clear to a more novice programmer, especially when their formatter.format function does have a "record" positional argument. |
Thank you for the clarification! I understand that the error message can be confusing, especially for novice users. Given that, I’ll go ahead and work on improving the documentation to make it clearer and help prevent misunderstandings related to un-initialized formatter classes. Let me know if there are any additional points I should consider while working on this! |
I think that should be it, thanks! |
@jlynchMicron Please check PR #127850 and let me know if it solves the issue. |
@Uvi-12 looks good to me! |
…thonGH-127850) (cherry picked from commit 5d66c55) Co-authored-by: UV <[email protected]>
…thonGH-127850) (cherry picked from commit 5d66c55) Co-authored-by: UV <[email protected]>
…H-127850) (#130392) (cherry picked from commit 5d66c55) Co-authored-by: UV <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
Documentation
https://docs.python.org/3/library/logging.html#logging.Handler.setFormatter
When providing a logger handler with a formatter class, there is no documentation stating if that formatter class needs to be initialized before passing it as an argument. Through trial and error, I found that it needs to be initialized first. Please either clarify the documentation or have underlying code check to see if the formatter is initialized yet.
Problemed formatter configuration:
Error:

Fixed formatter configuration:
Purposed code check (from a custom logging module):
Linked PRs
The text was updated successfully, but these errors were encountered: