]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38586: setting logging.Handler .name property in fileConfig (GH-16918)
authorLucas Cimon <lucas.cimon@gmail.com>
Thu, 31 Oct 2019 08:06:25 +0000 (09:06 +0100)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Thu, 31 Oct 2019 08:06:25 +0000 (08:06 +0000)
Lib/logging/config.py
Lib/test/test_logging.py
Misc/NEWS.d/next/Library/2019-10-24-17-26-39.bpo-38586.cyq5nr.rst [new file with mode: 0644]

index 9dd35e11aab3954ba4ba980e23145375b4852ad6..4a3b8966ede1c098720a3d5e4effc6e867b30d04 100644 (file)
@@ -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)
index 74ccf48b7ebe2e5f8365a4765bf5952709166080..53b5bfc93f33efc9b4cf8b4031213e53c301bef4 100644 (file)
@@ -1591,6 +1591,30 @@ class ConfigFileTest(BaseTest):
         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 (file)
index 0000000..eac7bba
--- /dev/null
@@ -0,0 +1 @@
+Now :func:`~logging.config.fileConfig` correcty sets the .name of handlers loaded.