Skip to content
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

Allow logging.config.fileConfig to accept kwargs #75263

Closed
Preston-Landers mannequin opened this issue Jul 30, 2017 · 6 comments
Closed

Allow logging.config.fileConfig to accept kwargs #75263

Preston-Landers mannequin opened this issue Jul 30, 2017 · 6 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@Preston-Landers
Copy link
Mannequin

Preston-Landers mannequin commented Jul 30, 2017

BPO 31080
Nosy @vsajip, @Preston-Landers
PRs
  • bpo-31080: allow logging.config.fileConfig to accept kwargs and/or args. #2979
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2017-08-02.21:22:00.379>
    created_at = <Date 2017-07-30.17:10:10.388>
    labels = ['type-feature', 'library']
    title = 'Allow `logging.config.fileConfig` to accept kwargs'
    updated_at = <Date 2017-08-03.08:43:28.349>
    user = 'https://github.com/Preston-Landers'

    bugs.python.org fields:

    activity = <Date 2017-08-03.08:43:28.349>
    actor = 'vinay.sajip'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-08-02.21:22:00.379>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2017-07-30.17:10:10.388>
    creator = 'planders'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31080
    keywords = []
    message_count = 6.0
    messages = ['299502', '299586', '299632', '299671', '299677', '299691']
    nosy_count = 2.0
    nosy_names = ['vinay.sajip', 'planders']
    pr_nums = ['2979']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31080'
    versions = []

    @Preston-Landers
    Copy link
    Mannequin Author

    Preston-Landers mannequin commented Jul 30, 2017

    The function logging.config.fileConfig accepts args but it would be nice if it also accepted kwargs.

    A simple patch seems to do it:

    diff --git a/Lib/logging/config.py b/Lib/logging/config.py
    index d692514..4672b48 100644
    --- a/Lib/logging/config.py
    +++ b/Lib/logging/config.py
    @@ -145,7 +145,9 @@ def \_install_handlers(cp, formatters):
    			 klass = \_resolve(klass)
    		 args = section["args"]
    		 args = eval(args, vars(logging))
    -        h = klass(*args)
    \+        kwargs = section.get("kwargs", '{}')
    \+        kwargs = eval(kwargs, vars(logging))
    \+        h = klass(*args, \*\*kwargs)
    		 if "level" in section:
    			 level = section["level"]
    			 h.setLevel(level)
    

    Unless there are any objections I plan to submit a pull request. In my use case I have a Pyramid service which
    uses concurrent-log-handler and it seems better to be able to name keyword args for file configuration.

    @Preston-Landers Preston-Landers mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jul 30, 2017
    @Preston-Landers
    Copy link
    Mannequin Author

    Preston-Landers mannequin commented Jul 31, 2017

    This is the current state of my patch:

    master...Preston-Landers:bpo-31080-fileconfig

    It makes both args and kwargs optional in the config file. (Obviously, the actual handler may require args.)

    @vsajip
    Copy link
    Member

    vsajip commented Aug 1, 2017

    Yes, seems reasonable, but don't change Misc/NEWS directly in your patch - this is now done using the "blurb" tool. Installed into a Python 3 environment using "pip install blurb".

    @vsajip
    Copy link
    Member

    vsajip commented Aug 2, 2017

    New changeset 6ea56d2 by Vinay Sajip (Preston Landers) in branch 'master':
    bpo-31080: Allowed logging.config.fileConfig() to accept both args and kwargs. (GH-2979)
    6ea56d2

    @vsajip vsajip closed this as completed Aug 2, 2017
    @Preston-Landers
    Copy link
    Mannequin Author

    Preston-Landers mannequin commented Aug 2, 2017

    A colleague pointed out that I used single quotes in the defaults where the line uses double quotes for another argument. I'm not sure if this is considered a problem but I could submit an update if it is.

    @vsajip
    Copy link
    Member

    vsajip commented Aug 3, 2017

    No, that's OK - leave it as is, I'll consider it when next visiting the area.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant