bpo-38586: setting logging.Handler .name property in fileConfig (GH-16918)
https://github.com/python/cpython/commit/b15100fe7def8580c78ed16f0bb4b72b2ae... commit: b15100fe7def8580c78ed16f0bb4b72b2ae7af3f branch: master author: Lucas Cimon <lucas.cimon@gmail.com> committer: Vinay Sajip <vinay_sajip@yahoo.co.uk> date: 2019-10-31T08:06:25Z summary: bpo-38586: setting logging.Handler .name property in fileConfig (GH-16918) files: A Misc/NEWS.d/next/Library/2019-10-24-17-26-39.bpo-38586.cyq5nr.rst M Lib/logging/config.py M Lib/test/test_logging.py diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 9dd35e11aab39..4a3b8966ede1c 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -143,6 +143,7 @@ def _install_handlers(cp, formatters): kwargs = section.get("kwargs", '{}') kwargs = eval(kwargs, vars(logging)) h = klass(*args, **kwargs) + h.name = hand if "level" in section: level = section["level"] h.setLevel(level) diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 74ccf48b7ebe2..53b5bfc93f33e 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1591,6 +1591,30 @@ def test_logger_disabling(self): self.apply_config(self.disable_test, disable_existing_loggers=False) self.assertFalse(logger.disabled) + def test_config_set_handler_names(self): + test_config = """ + [loggers] + keys=root + + [handlers] + keys=hand1 + + [formatters] + keys=form1 + + [logger_root] + handlers=hand1 + + [handler_hand1] + class=StreamHandler + formatter=form1 + + [formatter_form1] + format=%(levelname)s ++ %(message)s + """ + self.apply_config(test_config) + self.assertEquals(logging.getLogger().handlers[0].name, 'hand1') + def test_defaults_do_no_interpolation(self): """bpo-33802 defaults should not get interpolated""" ini = textwrap.dedent(""" diff --git a/Misc/NEWS.d/next/Library/2019-10-24-17-26-39.bpo-38586.cyq5nr.rst b/Misc/NEWS.d/next/Library/2019-10-24-17-26-39.bpo-38586.cyq5nr.rst new file mode 100644 index 0000000000000..eac7bba082566 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-10-24-17-26-39.bpo-38586.cyq5nr.rst @@ -0,0 +1 @@ +Now :func:`~logging.config.fileConfig` correcty sets the .name of handlers loaded.
participants (1)
-
Vinay Sajip