diff options
Diffstat (limited to 'Lib/logging/config.py')
-rw-r--r-- | Lib/logging/config.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 560ca379a3..188061449d 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -24,13 +24,13 @@ Copyright (C) 2001-2013 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ -import sys, logging, logging.handlers, socket, struct, os, traceback, re -import types, io +import sys, logging, logging.handlers, socket, struct, traceback, re +import io try: import _thread as thread import threading -except ImportError: +except ImportError: #pragma: no cover thread = None from socketserver import ThreadingTCPServer, StreamRequestHandler @@ -98,9 +98,6 @@ def _resolve(name): def _strip_spaces(alist): return map(lambda x: x.strip(), alist) -def _encoded(s): - return s if isinstance(s, str) else s.encode('utf-8') - def _create_formatters(cp): """Create and return formatters""" flist = cp["formatters"]["keys"] @@ -215,7 +212,7 @@ def _install_loggers(cp, handlers, disable_existing): #avoid disabling child loggers of explicitly #named loggers. With a sorted list it is easier #to find the child loggers. - existing.sort(key=_encoded) + existing.sort() #We'll keep the list of existing loggers #which are children of named loggers here... child_loggers = [] @@ -603,7 +600,7 @@ class DictConfigurator(BaseConfigurator): #avoid disabling child loggers of explicitly #named loggers. With a sorted list it is easier #to find the child loggers. - existing.sort(key=_encoded) + existing.sort() #We'll keep the list of existing loggers #which are children of named loggers here... child_loggers = [] @@ -672,7 +669,8 @@ class DictConfigurator(BaseConfigurator): 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 +692,7 @@ class DictConfigurator(BaseConfigurator): 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 +716,7 @@ class DictConfigurator(BaseConfigurator): 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: @@ -806,7 +805,7 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT): and which you can join() when appropriate. To stop the server, call stopListening(). """ - if not thread: + if not thread: #pragma: no cover raise NotImplementedError("listen() needs threading to work") class ConfigStreamHandler(StreamRequestHandler): @@ -824,7 +823,6 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT): struct.pack(">L", n), followed by the config file. Uses fileConfig() to do the grunt work. """ - import tempfile try: conn = self.connection chunk = conn.recv(4) @@ -845,7 +843,7 @@ def listen(port=DEFAULT_LOGGING_CONFIG_PORT): file = io.StringIO(chunk) try: fileConfig(file) - except (KeyboardInterrupt, SystemExit): + except (KeyboardInterrupt, SystemExit): #pragma: no cover raise except: traceback.print_exc() |