gh-89258: Add a getChildren() method to logging.Logger. (GH-96444)

Co-authored-by: Éric <merwok@netwok.org>
This commit is contained in:
Vinay Sajip 2022-08-31 10:50:29 +01:00 committed by GitHub
parent f7e7bf161a
commit 29f1b0bb1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 0 deletions

View file

@ -3717,6 +3717,20 @@ class ChildLoggerTest(BaseTest):
self.assertIs(c2, logging.getLogger('abc.def.ghi'))
self.assertIs(c2, c3)
def test_get_children(self):
r = logging.getLogger()
l1 = logging.getLogger('foo')
l2 = logging.getLogger('foo.bar')
l3 = logging.getLogger('foo.bar.baz.bozz')
l4 = logging.getLogger('bar')
kids = r.getChildren()
expected = {l1, l4}
self.assertEqual(expected, kids & expected) # might be other kids for root
self.assertNotIn(l2, expected)
kids = l1.getChildren()
self.assertEqual({l2}, kids)
kids = l2.getChildren()
self.assertEqual(set(), kids)
class DerivedLogRecord(logging.LogRecord):
pass