[Python-checkins] cpython (3.3): Issue #17540: Added style to Formatter configuration by dict.

vinay.sajip python-checkins at python.org
Fri Mar 29 18:59:40 CET 2013


http://hg.python.org/cpython/rev/d6fe31ce789d
changeset:   83002:d6fe31ce789d
branch:      3.3
parent:      82997:e76952bd4fa5
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Fri Mar 29 17:56:54 2013 +0000
summary:
  Issue #17540: Added style to Formatter configuration by dict.

files:
  Lib/logging/config.py    |  6 ++++--
  Lib/test/test_logging.py |  5 ++++-
  Misc/NEWS                |  2 ++
  3 files changed, 10 insertions(+), 3 deletions(-)


diff --git a/Lib/logging/config.py b/Lib/logging/config.py
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -669,7 +669,8 @@
         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):
@@ -691,6 +692,7 @@
 
     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:
@@ -714,7 +716,7 @@
                 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
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -2398,7 +2398,8 @@
         "version": 1,
         "formatters": {
             "mySimpleFormatter": {
-                "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s"
+                "format": "%(asctime)s (%(name)s) %(levelname)s: %(message)s",
+                "style": "$"
             }
         },
         "handlers": {
@@ -2728,6 +2729,8 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,8 @@
 Library
 -------
 
+- Issue #17540: Added style to formatter configuration by dict.
+
 - Issue #17536: Add to webbrowser's browser list: www-browser, x-www-browser,
   iceweasel, iceape.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list