[Python-checkins] gh-90195: Unset logger disabled flag when configuring it. (GH-96530)

vsajip webhook-mailer at python.org
Sat Sep 3 08:38:51 EDT 2022


https://github.com/python/cpython/commit/ac4ddab405a36bd0e2b86bcd147b3a647b734492
commit: ac4ddab405a36bd0e2b86bcd147b3a647b734492
branch: main
author: Vinay Sajip <vinay_sajip at yahoo.co.uk>
committer: vsajip <vinay_sajip at yahoo.co.uk>
date: 2022-09-03T13:38:38+01:00
summary:

gh-90195: Unset logger disabled flag when configuring it. (GH-96530)

files:
M Lib/logging/config.py
M Lib/test/test_logging.py

diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 2b9d90c3ed5b..7cd16c643e9d 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -869,6 +869,7 @@ def configure_logger(self, name, config, incremental=False):
         """Configure a non-root logger from a dictionary."""
         logger = logging.getLogger(name)
         self.common_logger_config(logger, config, incremental)
+        logger.disabled = False
         propagate = config.get('propagate', None)
         if propagate is not None:
             logger.propagate = propagate
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 0c852fc1eda2..d70bfd6b09e1 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3677,6 +3677,35 @@ def test_config_queue_handler(self):
             msg = str(ctx.exception)
             self.assertEqual(msg, "Unable to configure handler 'ah'")
 
+    def test_90195(self):
+        # See gh-90195
+        config = {
+            'version': 1,
+            'disable_existing_loggers': False,
+            'handlers': {
+                'console': {
+                    'level': 'DEBUG',
+                    'class': 'logging.StreamHandler',
+                },
+            },
+            'loggers': {
+                'a': {
+                    'level': 'DEBUG',
+                    'handlers': ['console']
+                }
+            }
+        }
+        logger = logging.getLogger('a')
+        self.assertFalse(logger.disabled)
+        self.apply_config(config)
+        self.assertFalse(logger.disabled)
+        # Should disable all loggers ...
+        self.apply_config({'version': 1})
+        self.assertTrue(logger.disabled)
+        del config['disable_existing_loggers']
+        self.apply_config(config)
+        # Logger should be enabled, since explicitly mentioned
+        self.assertFalse(logger.disabled)
 
 class ManagerTest(BaseTest):
     def test_manager_loggerclass(self):



More information about the Python-checkins mailing list