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
gh-91513: add taskname to logging.LogRecord attributes
#92646
base: main
Are you sure you want to change the base?
Conversation
4a9cae1
to
27b9704
Compare
taskname to logging.LogRecord attributestaskname to logging.LogRecord attributes
27b9704
to
6e7dc2c
Compare
| @@ -360,6 +366,9 @@ def __init__(self, name, level, pathname, lineno, | |||
| self.process = os.getpid() | |||
| else: | |||
| self.process = None | |||
| if logAsyncioTasks: | |||
| aio = sys.modules.get('asyncio') | |||
| self.taskname = aio.current_task().get_name() | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If
asynciohasn't been imported,aioisNoneand this will fail withAttributeError. - If we aren't running any asyncio task right now,
current_task()will raiseRuntimeError.
In other words, this fails with or without the asyncio import:
#import asyncio
import logging
logging.error("blah blah")I think we should also make sure that self.taskname is always set to something, and just set it to None if logAsyncTasks is set to False or no asyncio task is running. See how it sets self.processName = None above.
This PR needs tests (which would have exposed the point that @Akuli makes) and it would also make sense to use taskName in preference to taskname. I know it's not PEP-8 compliant and all, but logging predated PEP-8 and it makes more sense to keep things consistent at a local level.
It would make sense to do something like:
if not logAsyncioTasks:
self.taskName = None
else:
aio = sys.modules.get('asyncio')
if aio is None:
self.taskName = None
else:
self.taskName = aio.current_task().get_name()or, more concisely,
self.taskName = None
if logAsyncioTasks:
aio = sys.modules.get('asyncio')
if aio:
self.taskName = aio.current_task().get_name() |
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
No description provided.