Commit 843c76e9 authored by Vinay Sajip's avatar Vinay Sajip

Issue #17540: Added style to Formatter configuration by dict.

parent 15b57042
...@@ -669,7 +669,8 @@ class DictConfigurator(BaseConfigurator): ...@@ -669,7 +669,8 @@ class DictConfigurator(BaseConfigurator):
else: else:
fmt = config.get('format', None) fmt = config.get('format', None)
dfmt = config.get('datefmt', None) dfmt = config.get('datefmt', None)
result = logging.Formatter(fmt, dfmt) style = config.get('style', '%')
result = logging.Formatter(fmt, dfmt, style)
return result return result
def configure_filter(self, config): def configure_filter(self, config):
...@@ -691,6 +692,7 @@ class DictConfigurator(BaseConfigurator): ...@@ -691,6 +692,7 @@ class DictConfigurator(BaseConfigurator):
def configure_handler(self, config): def configure_handler(self, config):
"""Configure a handler from a dictionary.""" """Configure a handler from a dictionary."""
config_copy = dict(config) # for restoring in case of error
formatter = config.pop('formatter', None) formatter = config.pop('formatter', None)
if formatter: if formatter:
try: try:
...@@ -714,7 +716,7 @@ class DictConfigurator(BaseConfigurator): ...@@ -714,7 +716,7 @@ class DictConfigurator(BaseConfigurator):
try: try:
th = self.config['handlers'][config['target']] th = self.config['handlers'][config['target']]
if not isinstance(th, logging.Handler): 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') raise TypeError('target not configured yet')
config['target'] = th config['target'] = th
except Exception as e: except Exception as e:
......
...@@ -2398,7 +2398,8 @@ class ConfigDictTest(BaseTest): ...@@ -2398,7 +2398,8 @@ class ConfigDictTest(BaseTest):
"version": 1, "version": 1,
"formatters": { "formatters": {
"mySimpleFormatter": { "mySimpleFormatter": {
"format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s" "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s",
"style": "$"
} }
}, },
"handlers": { "handlers": {
...@@ -2728,6 +2729,8 @@ class ConfigDictTest(BaseTest): ...@@ -2728,6 +2729,8 @@ class ConfigDictTest(BaseTest):
self.apply_config(self.out_of_order) self.apply_config(self.out_of_order)
handler = logging.getLogger('mymodule').handlers[0] handler = logging.getLogger('mymodule').handlers[0]
self.assertIsInstance(handler.target, logging.Handler) self.assertIsInstance(handler.target, logging.Handler)
self.assertIsInstance(handler.formatter._style,
logging.StringTemplateStyle)
def test_baseconfig(self): def test_baseconfig(self):
d = { d = {
......
...@@ -200,6 +200,8 @@ Core and Builtins ...@@ -200,6 +200,8 @@ Core and Builtins
Library Library
------- -------
- Issue #17540: Added style to formatter configuration by dict.
- Issue #17536: Add to webbrowser's browser list: www-browser, x-www-browser, - Issue #17536: Add to webbrowser's browser list: www-browser, x-www-browser,
iceweasel, iceape. iceweasel, iceape.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment