Skip to content

[3.10] gh-90195: Unset logger disabled flag when configuring it. (GH-96530) (GH-96533) #96533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/logging/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,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
Expand Down
34 changes: 32 additions & 2 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -3439,6 +3439,36 @@ def emit(self, record):
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 = []
Expand Down