diff --git a/Lib/logging/config.py b/Lib/logging/config.py index b0c0971ce71..dbfd2c62eed 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -672,7 +672,8 @@ def configure_formatter(self, config): else: fmt = config.get('format', None) dfmt = config.get('datefmt', None) - result = logging.Formatter(fmt, dfmt) + style = config.get('style', '%') + result = logging.Formatter(fmt, dfmt, style) return result def configure_filter(self, config): @@ -694,6 +695,7 @@ def add_filters(self, filterer, filters): def configure_handler(self, config): """Configure a handler from a dictionary.""" + config_copy = dict(config) # for restoring in case of error formatter = config.pop('formatter', None) if formatter: try: @@ -717,7 +719,7 @@ def configure_handler(self, config): try: th = self.config['handlers'][config['target']] if not isinstance(th, logging.Handler): - config['class'] = cname # restore for deferred configuration + config.update(config_copy) # restore for deferred cfg raise TypeError('target not configured yet') config['target'] = th except Exception as e: diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 11e812d87b7..fea2b00fe39 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -2449,7 +2449,8 @@ class ConfigDictTest(BaseTest): "version": 1, "formatters": { "mySimpleFormatter": { - "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s" + "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s", + "style": "$" } }, "handlers": { @@ -2851,6 +2852,8 @@ def test_out_of_order(self): self.apply_config(self.out_of_order) handler = logging.getLogger('mymodule').handlers[0] self.assertIsInstance(handler.target, logging.Handler) + self.assertIsInstance(handler.formatter._style, + logging.StringTemplateStyle) def test_baseconfig(self): d = { diff --git a/Misc/NEWS b/Misc/NEWS index de80e5fadfc..5c2879ade9d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -297,6 +297,8 @@ Core and Builtins Library ------- +- Issue #17540: Added style to formatter configuration by dict. + - Issue #16692: The ssl module now supports TLS 1.1 and TLS 1.2. Initial patch by Michele OrrĂ¹.