Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-32732 Extra kwargs of log() are ignored by LoggerAdapter #5463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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", {})) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean this code

extra = dict(extra_1, **kwargs.get('extra', {}))

Example:

Python 3.8.0a0 (heads/master:07a1892f82, Feb  1 2018, 07:58:09) 
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> extra_1 = None or {'firstname': 'Cyril'}
>>> kwargs = {'extra': {'lastname': 'Martin'}}
>>> extra = dict(extra_1, **kwargs.get('extra', {}))
>>> extra
{'firstname': 'Cyril', 'lastname': 'Martin'}
>>> 

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works.
I am a beginner in Python, so I don't know what is 'the pythonic way'. I don't understand why you dislike '{ **x, **y}'. But I found some criticisms about 'dict(x, **y)'

So should I really replace '{ **x, **y}' by 'dict(x, **y)' ?

return msg, kwargs

#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not ignore extra in logging method when a LoggerAdapter is configured. Patch by Cyril Martin