Issue
We have a way to set thread name: thread = threading.Thread(name='Very important thread', target=foo)
and after that get this name for logging purposes with %(thread)s:
in formatter.
Is it possible to do something like this with asyncio.Task
?
Solution
You can access the current task with:
asyncio.Task.current_task()
As any other python object, you can dynamically add some properties to a Task
. For example, add this to the first line of any of your coroutines that start a new task:
asyncio.Task.current_task().foo = "Bar"
asyncio.Task.current_task().name = "#{}".format(n)
Add a logging filter to output this data with your logger.
Answered By - Udi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.