Skip to content

Commit c3dbbc8

Browse files
authored
[3.10] gh-90195: Unset logger disabled flag when configuring it. (GH-96530) (GH-96533)
1 parent 7b163f8 commit c3dbbc8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

Lib/logging/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def configure_logger(self, name, config, incremental=False):
794794
"""Configure a non-root logger from a dictionary."""
795795
logger = logging.getLogger(name)
796796
self.common_logger_config(logger, config, incremental)
797+
logger.disabled = False
797798
propagate = config.get('propagate', None)
798799
if propagate is not None:
799800
logger.propagate = propagate

Lib/test/test_logging.py

Lines changed: 32 additions & 2 deletions
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
@@ -3439,6 +3439,36 @@ def emit(self, record):
34393439
logging.info('some log')
34403440
self.assertEqual(stderr.getvalue(), 'some log my_type\n')
34413441

3442+
def test_90195(self):
3443+
# See gh-90195
3444+
config = {
3445+
'version': 1,
3446+
'disable_existing_loggers': False,
3447+
'handlers': {
3448+
'console': {
3449+
'level': 'DEBUG',
3450+
'class': 'logging.StreamHandler',
3451+
},
3452+
},
3453+
'loggers': {
3454+
'a': {
3455+
'level': 'DEBUG',
3456+
'handlers': ['console']
3457+
}
3458+
}
3459+
}
3460+
logger = logging.getLogger('a')
3461+
self.assertFalse(logger.disabled)
3462+
self.apply_config(config)
3463+
self.assertFalse(logger.disabled)
3464+
# Should disable all loggers ...
3465+
self.apply_config({'version': 1})
3466+
self.assertTrue(logger.disabled)
3467+
del config['disable_existing_loggers']
3468+
self.apply_config(config)
3469+
# Logger should be enabled, since explicitly mentioned
3470+
self.assertFalse(logger.disabled)
3471+
34423472
class ManagerTest(BaseTest):
34433473
def test_manager_loggerclass(self):
34443474
logged = []

0 commit comments

Comments
 (0)