Skip to content

gh-91513: add taskname to logging.LogRecord attributes#92646

Closed
carlbordum wants to merge 1 commit intopython:mainfrom
carlbordum:91513-logrecord-taskname-attr
Closed

gh-91513: add taskname to logging.LogRecord attributes#92646
carlbordum wants to merge 1 commit intopython:mainfrom
carlbordum:91513-logrecord-taskname-attr

Conversation

@carlbordum
Copy link
Copy Markdown
Contributor

No description provided.

@carlbordum carlbordum requested a review from vsajip as a code owner May 10, 2022 22:37
@carlbordum carlbordum force-pushed the 91513-logrecord-taskname-attr branch from 4a9cae1 to 27b9704 Compare May 10, 2022 22:40
@carlbordum carlbordum changed the title gh-91578: add taskname to logging.LogRecord attributes gh-91513: add taskname to logging.LogRecord attributes May 10, 2022
@carlbordum carlbordum force-pushed the 91513-logrecord-taskname-attr branch from 27b9704 to 6e7dc2c Compare May 10, 2022 22:46
self.process = None
if logAsyncioTasks:
aio = sys.modules.get('asyncio')
self.taskname = aio.current_task().get_name()
Copy link
Copy Markdown
Contributor

@Akuli Akuli May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If asyncio hasn't been imported, aio is None and this will fail with AttributeError.
  • If we aren't running any asyncio task right now, current_task() will raise RuntimeError.

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.

Copy link
Copy Markdown
Member

@vsajip vsajip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() 

@bedevere-bot
Copy link
Copy Markdown

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@vsajip
Copy link
Copy Markdown
Member

vsajip commented May 25, 2022

There's been no response to my request for changes, and now there's another PR - #93193 - to cover the same functionality. I propose to close this PR in favour of the other.

@vsajip vsajip closed this May 25, 2022
@carlbordum
Copy link
Copy Markdown
Contributor Author

There's been no response to my request for changes, and now there's another PR - #93193 - to cover the same functionality. I propose to close this PR in favour of the other.

Sorry for making such an incomplete PR. I'll be more thorough next time.

@vsajip
Copy link
Copy Markdown
Member

vsajip commented May 27, 2022

That's OK, don't worry about it. What matters is that the functionality is now in there. Thanks for trying to improve logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants