Skip to content

Commit b15100f

Browse files
Lucas-Cvsajip
authored andcommitted
bpo-38586: setting logging.Handler .name property in fileConfig (GH-16918)
1 parent 79d4ed1 commit b15100f

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Lib/logging/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def _install_handlers(cp, formatters):
143143
kwargs = section.get("kwargs", '{}')
144144
kwargs = eval(kwargs, vars(logging))
145145
h = klass(*args, **kwargs)
146+
h.name = hand
146147
if "level" in section:
147148
level = section["level"]
148149
h.setLevel(level)

Lib/test/test_logging.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,30 @@ def test_logger_disabling(self):
15911591
self.apply_config(self.disable_test, disable_existing_loggers=False)
15921592
self.assertFalse(logger.disabled)
15931593

1594+
def test_config_set_handler_names(self):
1595+
test_config = """
1596+
[loggers]
1597+
keys=root
1598+
1599+
[handlers]
1600+
keys=hand1
1601+
1602+
[formatters]
1603+
keys=form1
1604+
1605+
[logger_root]
1606+
handlers=hand1
1607+
1608+
[handler_hand1]
1609+
class=StreamHandler
1610+
formatter=form1
1611+
1612+
[formatter_form1]
1613+
format=%(levelname)s ++ %(message)s
1614+
"""
1615+
self.apply_config(test_config)
1616+
self.assertEquals(logging.getLogger().handlers[0].name, 'hand1')
1617+
15941618
def test_defaults_do_no_interpolation(self):
15951619
"""bpo-33802 defaults should not get interpolated"""
15961620
ini = textwrap.dedent("""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Now :func:`~logging.config.fileConfig` correcty sets the .name of handlers loaded.

0 commit comments

Comments
 (0)