Skip to content

Commit 2b1d435

Browse files
committed
pythongh-90195: Unset logger disabled flag when configuring it. (pythonGH-96530)
(cherry picked from commit ac4ddab)
1 parent 79fe67f commit 2b1d435

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

Lib/logging/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ def configure_logger(self, name, config, incremental=False):
795795
"""Configure a non-root logger from a dictionary."""
796796
logger = logging.getLogger(name)
797797
self.common_logger_config(logger, config, incremental)
798+
logger.disabled = False
798799
propagate = config.get('propagate', None)
799800
if propagate is not None:
800801
logger.propagate = propagate

Lib/test/test_logging.py

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2001-2021 by Vinay Sajip. All Rights Reserved.
1+
# Copyright 2001-2022 by Vinay Sajip. All Rights Reserved.
22
#
33
# Permission to use, copy, modify, and distribute this software and its
44
# documentation for any purpose and without fee is hereby granted,
@@ -16,7 +16,7 @@
1616

1717
"""Test harness for the logging module. Run all tests.
1818
19-
Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
19+
Copyright (C) 2001-2022 Vinay Sajip. All Rights Reserved.
2020
"""
2121

2222
import logging
@@ -3504,6 +3504,35 @@ class NotAFilter: pass
35043504
{"version": 1, "root": {"level": "DEBUG", "filters": [filter_]}}
35053505
)
35063506

3507+
def test_90195(self):
3508+
# See gh-90195
3509+
config = {
3510+
'version': 1,
3511+
'disable_existing_loggers': False,
3512+
'handlers': {
3513+
'console': {
3514+
'level': 'DEBUG',
3515+
'class': 'logging.StreamHandler',
3516+
},
3517+
},
3518+
'loggers': {
3519+
'a': {
3520+
'level': 'DEBUG',
3521+
'handlers': ['console']
3522+
}
3523+
}
3524+
}
3525+
logger = logging.getLogger('a')
3526+
self.assertFalse(logger.disabled)
3527+
self.apply_config(config)
3528+
self.assertFalse(logger.disabled)
3529+
# Should disable all loggers ...
3530+
self.apply_config({'version': 1})
3531+
self.assertTrue(logger.disabled)
3532+
del config['disable_existing_loggers']
3533+
self.apply_config(config)
3534+
# Logger should be enabled, since explicitly mentioned
3535+
self.assertFalse(logger.disabled)
35073536

35083537
class ManagerTest(BaseTest):
35093538
def test_manager_loggerclass(self):

0 commit comments

Comments
 (0)