]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] gh-90195: Unset logger disabled flag when configuring it. (GH-96530) (GH-96533)
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Sat, 3 Sep 2022 14:10:04 +0000 (15:10 +0100)
committerGitHub <noreply@github.com>
Sat, 3 Sep 2022 14:10:04 +0000 (15:10 +0100)
Lib/logging/config.py
Lib/test/test_logging.py

index 3bc63b78621abae6b697f4f0d5b122ae5750a312..5cab008f8d126883f32cf231244bb33ea908fe59 100644 (file)
@@ -794,6 +794,7 @@ class DictConfigurator(BaseConfigurator):
         """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
index 920bbeb66006a186612e65545b8713adfccd5fb6..74e950450cfb2022d82401210029901b07e9959a 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2001-2021 by Vinay Sajip. All Rights Reserved.
+# Copyright 2001-2022 by Vinay Sajip. All Rights Reserved.
 #
 # Permission to use, copy, modify, and distribute this software and its
 # documentation for any purpose and without fee is hereby granted,
@@ -16,7 +16,7 @@
 
 """Test harness for the logging module. Run all tests.
 
-Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
+Copyright (C) 2001-2022 Vinay Sajip. All Rights Reserved.
 """
 
 import logging
@@ -3439,6 +3439,36 @@ class ConfigDictTest(BaseTest):
             logging.info('some log')
         self.assertEqual(stderr.getvalue(), 'some log my_type\n')
 
+    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):
         logged = []