Skip to content

Easier loggers traversal tree with a logger.getChildren method #89258

Description

@sblondon
mannequin
BPO 45095
Nosy @sblondon

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 = None
created_at = <Date 2021-09-03.17:01:49.814>
labels = ['type-feature', 'library', '3.11']
title = 'Easier loggers traversal tree with a logger.getChildren method'
updated_at = <Date 2021-09-03.17:01:49.814>
user = 'https://github.com/sblondon'

bugs.python.org fields:

activity = <Date 2021-09-03.17:01:49.814>
actor = 'sblondon'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-09-03.17:01:49.814>
creator = 'sblondon'
dependencies = []
files = []
hgrepos = []
issue_num = 45095
keywords = []
message_count = 1.0
messages = ['401006']
nosy_count = 1.0
nosy_names = ['sblondon']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue45095'
versions = ['Python 3.11']

Activity

  1. sblondon commented on Sep 3, 2021

    sblondonmannequin
    MannequinAuthor

    Currently, logging.root.manager.loggerDict is usable to do a homemade traversal of the loggers tree. However, it's not a public interface. Adding a 'logger.getChildren()' method would help to implement the traversal. The method would return a set of loggers.

    Usage example:
    >>> import logging
    >>> logging.basicConfig(level=logging.CRITICAL)
    >>> root_logger = logging.getLogger()
    <RootLogger root (CRITICAL)>
    >>> root_logger.getChildren()
    set()
    >>> a_logger = logging.getLogger("a")
    >>> root_logger.getChildren()
    {<Logger a. (CRITICAL)>}
    >>> logging.getLogger('a.b').setLevel(logging.DEBUG)
    >>> _ = logging.getLogger('a.c')
    >>> a_logger.getChildren()
    {<Logger a.c (CRITICAL)>, <Logger a.b (DEBUG)>}

    With such method, traverse the tree will be obvious to write with a recursive function.

    Use cases:

    • to check all the loggers are setted up correctly. I wrote a small function to get all loggers, and log on every level to check the real behaviour.
    • to draw the loggers tree like logging_tree library (https://pypi.org/project/logging_tree/). I didn't ask to logging_tree's maintainer but I don't think he would use such function because the library works for huge range of python releases.

    I plan to write a PR if someone thinks it's a good idea.

  2. added
    3.11only security fixes
    stdlibStandard Library Python modules in the Lib/ directory
    type-featureA feature request or enhancement
    on Sep 3, 2021
  3. transferred this issue fromon Apr 10, 2022
  4. added a commit that references this issue on Aug 31, 2022
  5. added
    3.12only security fixes
    and removed
    3.11only security fixes
    on Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions