mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193)
This commit is contained in:
parent
5185956527
commit
cc377063ef
5 changed files with 88 additions and 7 deletions
|
|
@ -64,20 +64,25 @@ _startTime = time.time()
|
|||
raiseExceptions = True
|
||||
|
||||
#
|
||||
# If you don't want threading information in the log, set this to zero
|
||||
# If you don't want threading information in the log, set this to False
|
||||
#
|
||||
logThreads = True
|
||||
|
||||
#
|
||||
# If you don't want multiprocessing information in the log, set this to zero
|
||||
# If you don't want multiprocessing information in the log, set this to False
|
||||
#
|
||||
logMultiprocessing = True
|
||||
|
||||
#
|
||||
# If you don't want process information in the log, set this to zero
|
||||
# If you don't want process information in the log, set this to False
|
||||
#
|
||||
logProcesses = True
|
||||
|
||||
#
|
||||
# If you don't want asyncio task information in the log, set this to False
|
||||
#
|
||||
logAsyncioTasks = True
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Level related stuff
|
||||
#---------------------------------------------------------------------------
|
||||
|
|
@ -361,6 +366,15 @@ class LogRecord(object):
|
|||
else:
|
||||
self.process = None
|
||||
|
||||
self.taskName = None
|
||||
if logAsyncioTasks:
|
||||
asyncio = sys.modules.get('asyncio')
|
||||
if asyncio:
|
||||
try:
|
||||
self.taskName = asyncio.current_task().get_name()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def __repr__(self):
|
||||
return '<LogRecord: %s, %s, %s, %s, "%s">'%(self.name, self.levelno,
|
||||
self.pathname, self.lineno, self.msg)
|
||||
|
|
@ -566,6 +580,7 @@ class Formatter(object):
|
|||
(typically at application startup time)
|
||||
%(thread)d Thread ID (if available)
|
||||
%(threadName)s Thread name (if available)
|
||||
%(taskName)s Task name (if available)
|
||||
%(process)d Process ID (if available)
|
||||
%(message)s The result of record.getMessage(), computed just as
|
||||
the record is emitted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue