FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193) by jackh-ncl · Pull Request #93193 · python/cpython · GitHub

Repository navigation

gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193) - #93193

Merged
vsajip merged 10 commits into
python:mainfrom
jackh-ncl:91513
May 26, 2022
Merged

vsajip merged 10 commits into
python:mainfrom
jackh-ncl:91513

Conversation

jackh-ncl commented May 25, 2022 •
edited
Loading

Copy link
Copy Markdown
Contributor

For: #91513

Continuing on from carlbordum@6e7dc2c 😃

Can test using:

import asyncio
import logging

FORMAT = '%(processName)s - %(process)s - %(threadName)s - %(thread)d - %(taskName)s - %(pathname)s - %(asctime)s - %(message)s'
logging.basicConfig(format=FORMAT)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


async def log_some_stuff(name):
    logger.info(name)
    await asyncio.sleep(1)


async def spawn_tasks():
    await asyncio.gather(
        log_some_stuff('hello'),
        log_some_stuff('cheese')
    )


if __name__ == '__main__':
    asyncio.run(spawn_tasks())
    logger.info('Finished')
$ uname -a
Darwin ... 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:47:26 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64

$ ./python.exe -m test -j8
...
== Tests result: SUCCESS ==

407 tests OK.

29 tests skipped:
    test_curses test_dbm_gnu test_devpoll test_epoll test_gdb
    test_idle test_ioctl test_launcher test_msilib
    test_multiprocessing_fork test_ossaudiodev test_smtpnet
    test_socketserver test_spwd test_ssl test_startfile test_tcl
    test_tix test_tk test_ttk_guionly test_ttk_textonly test_turtle
    test_urllib2net test_urllibnet test_winconsoleio test_winreg
    test_winsound test_xmlrpc_net test_zipfile64

Total duration: 3 min 35 sec
Tests result: SUCCESS

Copy link
Copy Markdown

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

Comment thread Lib/test/test_logging.py
logging.logAsyncioTasks = False
runner.run(log_record(self.assertIsNone))
finally:
asyncio.set_event_loop_policy(None)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Tearing down, else we end up with:

== Tests result: SUCCESS ==

406 tests OK.

1 test altered the execution environment:
    test_logging

29 tests skipped:
    test_curses test_dbm_gnu test_devpoll test_epoll test_gdb
    test_idle test_ioctl test_launcher test_msilib
    test_multiprocessing_fork test_ossaudiodev test_smtpnet
    test_socketserver test_spwd test_ssl test_startfile test_tcl
    test_tix test_tk test_ttk_guionly test_ttk_textonly test_turtle
    test_urllib2net test_urllibnet test_winconsoleio test_winreg
    test_winsound test_xmlrpc_net test_zipfile64

jackh-ncl changed the title Add 'asyncio' taskName to logging attributes 91513 - Add 'asyncio' taskName to logging attributes May 25, 2022
jackh-ncl changed the title 91513 - Add 'asyncio' taskName to logging attributes #91513 - Add 'asyncio' taskName to logging attributes May 25, 2022
jackh-ncl changed the title #91513 - Add 'asyncio' taskName to logging attributes gh-91513: Add 'asyncio' taskName to logging attributes May 25, 2022
jackh-ncl marked this pull request as ready for review May 25, 2022 06:33
jackh-ncl requested a review from vsajip as a code owner May 25, 2022 06:33
Comment thread Doc/library/logging.rst Outdated
Comment thread Lib/logging/__init__.py
Comment thread Lib/test/test_logging.py Outdated
Comment thread Lib/test/test_logging.py
Comment thread Lib/test/test_logging.py
Comment thread Lib/test/test_logging.py

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.

Minor refactor in LogRecord.__init__ as per suggestions.

Fixed typo in docs.
Comment thread Lib/test/test_logging.py
jackh-ncl requested a review from vsajip May 25, 2022 08:36

vsajip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Just one suggested minor change, and one question.

Comment thread Lib/test/test_logging.py Outdated
with open('test.log', encoding='utf-8') as f:
data = f.read().strip()
os.remove('test.log')
self.assertEqual('Task-1 - hello world', data)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How can we be sure the task name will always be Task-1? What if more asyncio tasks are added in other tests which run before this one? Will the numbering still start at 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Have changed it to an assertRegex, similar to:

match1 = re.match(r"^<Task pending name='Task-(\d+)'", repr(t1))
self.assertIsNotNone(match1)

…istent.

Removed percent styling from News entry.
jackh-ncl requested a review from vsajip May 25, 2022 15:41

vsajip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The Azure pipeline check is failing - this is usually due to whitespace normalization issues. Can you please run make patchcheck and fixup anything that's found?

Copy link
Copy Markdown
Contributor Author

Pipelines looking green after pulling most recent main branch.

jackh-ncl requested a review from vsajip May 25, 2022 17:27
vsajip changed the title gh-91513: Add 'asyncio' taskName to logging attributes gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193) May 26, 2022
vsajip merged commit cc37706 into python:main May 26, 2022
Comment thread Lib/test/test_logging.py
with open('test.log', encoding='utf-8') as f:
data = f.read().strip()
os.remove('test.log')
self.assertRegex(data, r'Task-\d+ - hello world')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
handler = None
try:
    ...
finally:
    asyncio.set_event_loop_policy(None)
    if handler is not None:
        handler.close()
    if os.path.exists('test.log'):
        ....

to prevent sub-exceptions in the finally block if there is an exception/assertion error in the try block ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would have put the self.assertRegex(data, r'Task-\d+ - hello world') at the end of the try block too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, that's a fair point. This test probably needs tidying up a little.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I was following the pattern of the encoding tests above this one.
Happy to raise a new PR and fix it up along with the others.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's OK, I've just done it. I'm working on logging tests for something else.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It's #93265.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL