mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
This commit is contained in:
parent
73c22e9df2
commit
804899b4ab
4 changed files with 62 additions and 1 deletions
|
@ -1736,6 +1736,23 @@ class ManagerTest(BaseTest):
|
|||
self.assertEqual(logged, ['should appear in logged'])
|
||||
|
||||
|
||||
class ChildLoggerTest(BaseTest):
|
||||
def test_child_loggers(self):
|
||||
r = logging.getLogger()
|
||||
l1 = logging.getLogger('abc')
|
||||
l2 = logging.getLogger('def.ghi')
|
||||
c1 = r.getChild('xyz')
|
||||
c2 = r.getChild('uvw.xyz')
|
||||
self.assertTrue(c1 is logging.getLogger('xyz'))
|
||||
self.assertTrue(c2 is logging.getLogger('uvw.xyz'))
|
||||
c1 = l1.getChild('def')
|
||||
c2 = c1.getChild('ghi')
|
||||
c3 = l1.getChild('def.ghi')
|
||||
self.assertTrue(c1 is logging.getLogger('abc.def'))
|
||||
self.assertTrue(c2 is logging.getLogger('abc.def.ghi'))
|
||||
self.assertTrue(c2 is c3)
|
||||
|
||||
|
||||
# Set the locale to the platform-dependent default. I have no idea
|
||||
# why the test does this, but in any case we save the current locale
|
||||
# first and restore it at the end.
|
||||
|
@ -1744,7 +1761,8 @@ def test_main():
|
|||
run_unittest(BuiltinLevelsTest, BasicFilterTest,
|
||||
CustomLevelsAndFiltersTest, MemoryHandlerTest,
|
||||
ConfigFileTest, SocketHandlerTest, MemoryTest,
|
||||
EncodingTest, WarningsTest, ConfigDictTest, ManagerTest)
|
||||
EncodingTest, WarningsTest, ConfigDictTest, ManagerTest,
|
||||
ChildLoggerTest)
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue