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

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

Closed
sblondon mannequin opened this issue Sep 3, 2021 · 1 comment
Closed

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

sblondon mannequin opened this issue Sep 3, 2021 · 1 comment
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sblondon
Copy link
Mannequin

sblondon mannequin commented Sep 3, 2021

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']

@sblondon
Copy link
Mannequin Author

sblondon mannequin commented Sep 3, 2021

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.

@sblondon sblondon mannequin added 3.11 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Sep 3, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
vsajip added a commit that referenced this issue Aug 31, 2022
@vsajip vsajip added 3.12 bugs and security fixes and removed 3.11 only security fixes labels Sep 2, 2022
@vsajip vsajip closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Development

No branches or pull requests

1 participant