mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-89258: Add a getChildren() method to logging.Logger. (GH-96444)
Co-authored-by: Éric <merwok@netwok.org>
This commit is contained in:
parent
f7e7bf161a
commit
29f1b0bb1f
4 changed files with 47 additions and 0 deletions
|
@ -1828,6 +1828,25 @@ class Logger(Filterer):
|
|||
suffix = '.'.join((self.name, suffix))
|
||||
return self.manager.getLogger(suffix)
|
||||
|
||||
def getChildren(self):
|
||||
|
||||
def _hierlevel(logger):
|
||||
if logger is logger.manager.root:
|
||||
return 0
|
||||
return 1 + logger.name.count('.')
|
||||
|
||||
d = self.manager.loggerDict
|
||||
_acquireLock()
|
||||
try:
|
||||
# exclude PlaceHolders - the last check is to ensure that lower-level
|
||||
# descendants aren't returned - if there are placeholders, a logger's
|
||||
# parent field might point to a grandparent or ancestor thereof.
|
||||
return set(item for item in d.values()
|
||||
if isinstance(item, Logger) and item.parent is self and
|
||||
_hierlevel(item) == 1 + _hierlevel(item.parent))
|
||||
finally:
|
||||
_releaseLock()
|
||||
|
||||
def __repr__(self):
|
||||
level = getLevelName(self.getEffectiveLevel())
|
||||
return '<%s %s (%s)>' % (self.__class__.__name__, self.name, level)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue