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

logging.getLogger accepts name='root' leading to confusion #81923

Closed
yurzo mannequin opened this issue Aug 1, 2019 · 3 comments
Closed

logging.getLogger accepts name='root' leading to confusion #81923

yurzo mannequin opened this issue Aug 1, 2019 · 3 comments
Assignees
Labels
3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@yurzo
Copy link
Mannequin

yurzo mannequin commented Aug 1, 2019

BPO 37742
Nosy @rhettinger, @vsajip, @yurzo
PRs
  • bpo-37742: Return the root logger when logging.getLogger('root') is c… #15077
  • 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 = 'https://github.com/vsajip'
    closed_at = <Date 2019-08-02.16:01:28.443>
    created_at = <Date 2019-08-01.23:22:33.930>
    labels = ['type-feature', 'library', '3.9']
    title = "logging.getLogger accepts name='root' leading to confusion"
    updated_at = <Date 2019-08-02.16:01:28.442>
    user = 'https://github.com/yurzo'

    bugs.python.org fields:

    activity = <Date 2019-08-02.16:01:28.442>
    actor = 'vinay.sajip'
    assignee = 'vinay.sajip'
    closed = True
    closed_date = <Date 2019-08-02.16:01:28.443>
    closer = 'vinay.sajip'
    components = ['Library (Lib)']
    creation = <Date 2019-08-01.23:22:33.930>
    creator = 'yurzo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 37742
    keywords = ['patch']
    message_count = 3.0
    messages = ['348877', '348888', '348905']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'vinay.sajip', 'yurzo']
    pr_nums = ['15077']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue37742'
    versions = ['Python 3.9']

    @yurzo
    Copy link
    Mannequin Author

    yurzo mannequin commented Aug 1, 2019

    'root' should be a reserved name to avoid this:

    >>> import logging
    >>> a = logging.getLogger()
    >>> b = logging.getLogger('root')
    >>> a.name
    'root'
    >>> b.name
    'root'
    >>> a is b
    False

    @yurzo yurzo mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 1, 2019
    @rhettinger
    Copy link
    Contributor

    It looks like the issue is that the root logger is missing from the manager's loggerDict.

    A suggested fix is to change the creation of the loggerDict in the Manager class:

    •   self.loggerDict = {}
      

    + self.loggerDict = {rootnode.name: rootnode}

    This may have been omitted from the initial design to avoid reference cycles; however, with the advent of garbage collection this should no longer be an issue. Alternatively, a weak reference could be used.

    @vsajip vsajip self-assigned this Aug 2, 2019
    @vsajip
    Copy link
    Member

    vsajip commented Aug 2, 2019

    New changeset cb65b3a by Vinay Sajip in branch 'master':
    bpo-37742: Return the root logger when logging.getLogger('root') is c… (bpo-15077)
    cb65b3a

    @vsajip vsajip closed this as completed Aug 2, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    kdeldycke added a commit to kdeldycke/click-extra that referenced this issue May 8, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants