]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17521: Corrected non-enabling of logger following two calls to fileConfig().
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 23 Mar 2013 11:18:10 +0000 (11:18 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 23 Mar 2013 11:18:10 +0000 (11:18 +0000)
Lib/logging/config.py
Lib/test/test_logging.py
Misc/NEWS

index e3c93247aff472923b5302f91ba75c3778eaf691..37729d8983e294ac27ce2ab941e63f2393c69c44 100644 (file)
@@ -260,8 +260,8 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
             logger.level = logging.NOTSET
             logger.handlers = []
             logger.propagate = 1
-        elif disable_existing_loggers:
-            logger.disabled = 1
+        else:
+            logger.disabled = disable_existing_loggers
 
 
 
index a8c44501e5d31b59ed1424e6dcd148ecfc6c1c02..31bc48e353ad926642770e74a4921f39f7035b15 100644 (file)
@@ -714,9 +714,30 @@ class ConfigFileTest(BaseTest):
     datefmt=
     """
 
-    def apply_config(self, conf):
+    disable_test = """
+    [loggers]
+    keys=root
+
+    [handlers]
+    keys=screen
+
+    [formatters]
+    keys=
+
+    [logger_root]
+    level=DEBUG
+    handlers=screen
+
+    [handler_screen]
+    level=DEBUG
+    class=StreamHandler
+    args=(sys.stdout,)
+    formatter=
+    """
+
+    def apply_config(self, conf, **kwargs):
         file = cStringIO.StringIO(textwrap.dedent(conf))
-        logging.config.fileConfig(file)
+        logging.config.fileConfig(file, **kwargs)
 
     def test_config0_ok(self):
         # A simple config file which overrides the default settings.
@@ -820,6 +841,15 @@ class ConfigFileTest(BaseTest):
             # Original logger output is empty.
             self.assert_log_lines([])
 
+    def test_logger_disabling(self):
+        self.apply_config(self.disable_test)
+        logger = logging.getLogger('foo')
+        self.assertFalse(logger.disabled)
+        self.apply_config(self.disable_test)
+        self.assertTrue(logger.disabled)
+        self.apply_config(self.disable_test, disable_existing_loggers=False)
+        self.assertFalse(logger.disabled)
+
 class LogRecordStreamHandler(StreamRequestHandler):
 
     """Handler for a streaming logging request. It saves the log message in the
index 46d03dc14f22d71f64c254629296a972ad801c56..f1722469652e39ac4f49d10930ba61354871db91 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -216,6 +216,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #17521: Corrected non-enabling of logger following two calls to
+  fileConfig().
+
 - Issue #17508: Corrected MemoryHandler configuration in dictConfig() where
   the target handler wasn't configured first.