diff options
author | jackh-ncl <1750152+jackh-ncl@users.noreply.github.com> | 2022-05-26 08:30:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-26 08:30:51 (GMT) |
commit | cc377063ef3ef99edce00e0c706809d9510e2bed (patch) | |
tree | 79b7df791bf0f18724d2f2fd078f4ca7ca426250 /Lib/logging | |
parent | 518595652759462b13904df767f69b8cc2c61143 (diff) | |
download | cpython-cc377063ef3ef99edce00e0c706809d9510e2bed.zip cpython-cc377063ef3ef99edce00e0c706809d9510e2bed.tar.gz cpython-cc377063ef3ef99edce00e0c706809d9510e2bed.tar.bz2 |
gh-91513: Add 'asyncio' taskName to logging LogRecord attributes. (GH-93193)
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 79e4b7d..e7636e1 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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 |