mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-138162: Fix logging.LoggerAdapter with merge_extra=True and without the extra argument (GH-140511)
This commit is contained in:
parent
622d97b8bb
commit
327dbbedff
4 changed files with 50 additions and 11 deletions
|
|
@ -1849,9 +1849,9 @@ class LoggerAdapter(object):
|
|||
|
||||
def __init__(self, logger, extra=None, merge_extra=False):
|
||||
"""
|
||||
Initialize the adapter with a logger and a dict-like object which
|
||||
provides contextual information. This constructor signature allows
|
||||
easy stacking of LoggerAdapters, if so desired.
|
||||
Initialize the adapter with a logger and an optional dict-like object
|
||||
which provides contextual information. This constructor signature
|
||||
allows easy stacking of LoggerAdapters, if so desired.
|
||||
|
||||
You can effectively pass keyword arguments as shown in the
|
||||
following example:
|
||||
|
|
@ -1882,8 +1882,9 @@ def process(self, msg, kwargs):
|
|||
Normally, you'll only need to override this one method in a
|
||||
LoggerAdapter subclass for your specific needs.
|
||||
"""
|
||||
if self.merge_extra and "extra" in kwargs:
|
||||
kwargs["extra"] = {**self.extra, **kwargs["extra"]}
|
||||
if self.merge_extra and kwargs.get("extra") is not None:
|
||||
if self.extra is not None:
|
||||
kwargs["extra"] = {**self.extra, **kwargs["extra"]}
|
||||
else:
|
||||
kwargs["extra"] = self.extra
|
||||
return msg, kwargs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue