From 1e9f56e83feff6d0bce37c1f563f2fde72f8dcef Mon Sep 17 00:00:00 2001 From: Cyril Martin Date: Wed, 31 Jan 2018 17:35:34 +0100 Subject: [PATCH] Extra kwargs of log() are ignored by LoggerAdapter - extra kwargs given to Logger#log are ignored when we configure a LoggerAdapter (same for: debug, info, warning etc). - LoggerAdapter processes only extra kwargs given during its __init__ - I expect extras are merged Signed-off-by: Cyril Martin --- Lib/logging/__init__.py | 4 ++-- .../next/Library/2018-01-31-19-56-00.bpo-32732.mcOOli.rst | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-01-31-19-56-00.bpo-32732.mcOOli.rst diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index 9f2c0f0c58a39e..a75bc50a4a27e0 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1647,7 +1647,7 @@ def __init__(self, logger, extra): adapter = LoggerAdapter(someLogger, dict(p1=v1, p2="v2")) """ self.logger = logger - self.extra = extra + self.extra = extra or {} def process(self, msg, kwargs): """ @@ -1659,7 +1659,7 @@ def process(self, msg, kwargs): Normally, you'll only need to override this one method in a LoggerAdapter subclass for your specific needs. """ - kwargs["extra"] = self.extra + kwargs["extra"] = { **self.extra, **(kwargs.get("extra", {})) } return msg, kwargs # diff --git a/Misc/NEWS.d/next/Library/2018-01-31-19-56-00.bpo-32732.mcOOli.rst b/Misc/NEWS.d/next/Library/2018-01-31-19-56-00.bpo-32732.mcOOli.rst new file mode 100644 index 00000000000000..3b0af3dc6081cd --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-01-31-19-56-00.bpo-32732.mcOOli.rst @@ -0,0 +1 @@ +Do not ignore extra in logging method when a LoggerAdapter is configured. Patch by Cyril Martin