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

Conversation

mcoolive
Copy link

@mcoolive mcoolive commented Jan 31, 2018

  • LoggerAdapter processes only extra kwargs given during its init. So extra kwargs, given to Logger#log are ignored when we configure a LoggerAdapter (same for: debug, info, warning etc).
  • I expect extras are merged. More precisely, I expect local extra override the ones given in init.

https://bugs.python.org/issue32732

@the-knights-who-say-ni
Copy link

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!

@mcoolive mcoolive changed the title Extra kwargs of log() are ignored by LoggerAdapter Extra kwargs of log() are ignored by LoggerAdapter #32732 Jan 31, 2018
@mcoolive mcoolive changed the title Extra kwargs of log() are ignored by LoggerAdapter #32732 bpo-32732 Extra kwargs of log() are ignored by LoggerAdapter Jan 31, 2018
- 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]>
@@ -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)' ?

@vsajip
Copy link
Member

vsajip commented Feb 28, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants