diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-03-07 17:49:33 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-03-07 17:49:33 (GMT) |
commit | 3f84b07816fc63dd4996146bdd757f6bc81c54a9 (patch) | |
tree | 2f28c6e2c86bc0c82ad9884b771d37c0b5da643c /Lib/test | |
parent | d86e4c86733736f938100bae85b6eb3fadf5f02c (diff) | |
download | cpython-3f84b07816fc63dd4996146bdd757f6bc81c54a9.zip cpython-3f84b07816fc63dd4996146bdd757f6bc81c54a9.tar.gz cpython-3f84b07816fc63dd4996146bdd757f6bc81c54a9.tar.bz2 |
Issue #11424: Fix bug in determining child loggers.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_logging.py | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 05a7f9e..9b36350 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -553,6 +553,38 @@ class ConfigFileTest(BaseTest): datefmt= """ + # config1a moves the handler to the root. + config1a = """ + [loggers] + keys=root,parser + + [handlers] + keys=hand1 + + [formatters] + keys=form1 + + [logger_root] + level=WARNING + handlers=hand1 + + [logger_parser] + level=DEBUG + handlers= + propagate=1 + qualname=compiler.parser + + [handler_hand1] + class=StreamHandler + level=NOTSET + formatter=form1 + args=(sys.stdout,) + + [formatter_form1] + format=%(levelname)s ++ %(message)s + datefmt= + """ + # config2 has a subtle configuration error that should be reported config2 = config1.replace("sys.stdout", "sys.stbout") @@ -631,6 +663,44 @@ class ConfigFileTest(BaseTest): datefmt= """ + # config7 adds a compiler logger. + config7 = """ + [loggers] + keys=root,parser,compiler + + [handlers] + keys=hand1 + + [formatters] + keys=form1 + + [logger_root] + level=WARNING + handlers=hand1 + + [logger_compiler] + level=DEBUG + handlers= + propagate=1 + qualname=compiler + + [logger_parser] + level=DEBUG + handlers= + propagate=1 + qualname=compiler.parser + + [handler_hand1] + class=StreamHandler + level=NOTSET + formatter=form1 + args=(sys.stdout,) + + [formatter_form1] + format=%(levelname)s ++ %(message)s + datefmt= + """ + def apply_config(self, conf): try: fn = tempfile.mktemp(".ini") @@ -700,6 +770,49 @@ class ConfigFileTest(BaseTest): def test_config6_ok(self): self.test_config1_ok(config=self.config6) + def test_config7_ok(self): + with captured_stdout() as output: + self.apply_config(self.config1a) + logger = logging.getLogger("compiler.parser") + # See issue #11424. compiler-hyphenated sorts + # between compiler and compiler.xyz and this + # was preventing compiler.xyz from being included + # in the child loggers of compiler because of an + # overzealous loop termination condition. + hyphenated = logging.getLogger('compiler-hyphenated') + # All will output a message + logger.info(self.next_message()) + logger.error(self.next_message()) + hyphenated.critical(self.next_message()) + self.assert_log_lines([ + ('INFO', '1'), + ('ERROR', '2'), + ('CRITICAL', '3'), + ], stream=output) + # Original logger output is empty. + self.assert_log_lines([]) + with captured_stdout() as output: + self.apply_config(self.config7) + logger = logging.getLogger("compiler.parser") + self.assertFalse(logger.disabled) + # Both will output a message + logger.info(self.next_message()) + logger.error(self.next_message()) + logger = logging.getLogger("compiler.lexer") + # Both will output a message + logger.info(self.next_message()) + logger.error(self.next_message()) + # Will not appear + hyphenated.critical(self.next_message()) + self.assert_log_lines([ + ('INFO', '4'), + ('ERROR', '5'), + ('INFO', '6'), + ('ERROR', '7'), + ], stream=output) + # Original logger output is empty. + self.assert_log_lines([]) + class LogRecordStreamHandler(StreamRequestHandler): """Handler for a streaming logging request. It saves the log message in the |