diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2022-08-31 09:50:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 09:50:29 (GMT) |
commit | 29f1b0bb1ff73dcc28f0ca7e11794141b6de58c9 (patch) | |
tree | daf510cf627f7543a608ee60799fcf2a059d4660 /Lib/logging | |
parent | f7e7bf161aaec5a5cffdcec7c97e1f09e445421b (diff) | |
download | cpython-29f1b0bb1ff73dcc28f0ca7e11794141b6de58c9.zip cpython-29f1b0bb1ff73dcc28f0ca7e11794141b6de58c9.tar.gz cpython-29f1b0bb1ff73dcc28f0ca7e11794141b6de58c9.tar.bz2 |
gh-89258: Add a getChildren() method to logging.Logger. (GH-96444)
Co-authored-by: Éric <merwok@netwok.org>
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/__init__.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index c3208a2..86e1efe 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -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) |