-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
0e7b273
to
ee4e921
Compare
ee4e921
to
9614bd6
Compare
- 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 <[email protected]>
9614bd6
to
1e9f56e
Compare
@@ -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", {})) } |
There was a problem hiding this comment.
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'}
>>>
There was a problem hiding this comment.
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)'
- https://stackoverflow.com/questions/38987/how-to-merge-two-dictionaries-in-a-single-expression
- https://mail.python.org/pipermail/python-dev/2010-April/099459.html
So should I really replace '{ **x, **y}' by 'dict(x, **y)' ?
I am minded to close this pull request without merging, because the behaviour is not a bug - it works the way it does by design. It is generally better to just raise an issue to ensure that this really is an issue that needs resolving, otherwise the time you spend crafting a PR is wasted. This holds doubly true if you are a Python beginner. |
https://bugs.python.org/issue32732