From 19c7b30759ac38730a8145a58340cd85899734bc Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 3 Oct 2016 19:45:50 +0100 Subject: Closes #28335: used 'raise from' in logging configuration code. --- Lib/logging/config.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'Lib/logging/config.py') diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 8a99923bf3..65d70daf5a 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -1,4 +1,4 @@ -# Copyright 2001-2014 by Vinay Sajip. All Rights Reserved. +# Copyright 2001-2016 by Vinay Sajip. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, @@ -19,7 +19,7 @@ Configuration functions for the logging package for Python. The core package is based on PEP 282 and comments thereto in comp.lang.python, and influenced by Apache's log4j system. -Copyright (C) 2001-2014 Vinay Sajip. All Rights Reserved. +Copyright (C) 2001-2016 Vinay Sajip. All Rights Reserved. To use, simply 'import logging' and log away! """ @@ -509,21 +509,21 @@ class DictConfigurator(BaseConfigurator): handler.setLevel(logging._checkLevel(level)) except Exception as e: raise ValueError('Unable to configure handler ' - '%r: %s' % (name, e)) + '%r' % name) from e loggers = config.get('loggers', EMPTY_DICT) for name in loggers: try: self.configure_logger(name, loggers[name], True) except Exception as e: raise ValueError('Unable to configure logger ' - '%r: %s' % (name, e)) + '%r' % name) from e root = config.get('root', None) if root: try: self.configure_root(root, True) except Exception as e: raise ValueError('Unable to configure root ' - 'logger: %s' % e) + 'logger') from e else: disable_existing = config.pop('disable_existing_loggers', True) @@ -538,7 +538,7 @@ class DictConfigurator(BaseConfigurator): formatters[name]) except Exception as e: raise ValueError('Unable to configure ' - 'formatter %r: %s' % (name, e)) + 'formatter %r' % name) from e # Next, do filters - they don't refer to anything else, either filters = config.get('filters', EMPTY_DICT) for name in filters: @@ -546,7 +546,7 @@ class DictConfigurator(BaseConfigurator): filters[name] = self.configure_filter(filters[name]) except Exception as e: raise ValueError('Unable to configure ' - 'filter %r: %s' % (name, e)) + 'filter %r' % name) from e # Next, do handlers - they refer to formatters and filters # As handlers can refer to other handlers, sort the keys @@ -559,11 +559,11 @@ class DictConfigurator(BaseConfigurator): handler.name = name handlers[name] = handler except Exception as e: - if 'target not configured yet' in str(e): + if 'Unable to set target handler' in str(e): deferred.append(name) else: raise ValueError('Unable to configure handler ' - '%r: %s' % (name, e)) + '%r' % name) from e # Now do any that were deferred for name in deferred: @@ -573,7 +573,7 @@ class DictConfigurator(BaseConfigurator): handlers[name] = handler except Exception as e: raise ValueError('Unable to configure handler ' - '%r: %s' % (name, e)) + '%r' % name) from e # Next, do loggers - they refer to handlers and filters @@ -612,7 +612,7 @@ class DictConfigurator(BaseConfigurator): self.configure_logger(name, loggers[name]) except Exception as e: raise ValueError('Unable to configure logger ' - '%r: %s' % (name, e)) + '%r' % name) from e #Disable any old loggers. There's no point deleting #them as other threads may continue to hold references @@ -637,7 +637,7 @@ class DictConfigurator(BaseConfigurator): self.configure_root(root) except Exception as e: raise ValueError('Unable to configure root ' - 'logger: %s' % e) + 'logger') from e finally: logging._releaseLock() @@ -684,7 +684,7 @@ class DictConfigurator(BaseConfigurator): try: filterer.addFilter(self.config['filters'][f]) except Exception as e: - raise ValueError('Unable to add filter %r: %s' % (f, e)) + raise ValueError('Unable to add filter %r' % f) from e def configure_handler(self, config): """Configure a handler from a dictionary.""" @@ -695,7 +695,7 @@ class DictConfigurator(BaseConfigurator): formatter = self.config['formatters'][formatter] except Exception as e: raise ValueError('Unable to set formatter ' - '%r: %s' % (formatter, e)) + '%r' % formatter) from e level = config.pop('level', None) filters = config.pop('filters', None) if '()' in config: @@ -717,7 +717,7 @@ class DictConfigurator(BaseConfigurator): config['target'] = th except Exception as e: raise ValueError('Unable to set target handler ' - '%r: %s' % (config['target'], e)) + '%r' % config['target']) from e elif issubclass(klass, logging.handlers.SMTPHandler) and\ 'mailhost' in config: config['mailhost'] = self.as_tuple(config['mailhost']) @@ -755,7 +755,7 @@ class DictConfigurator(BaseConfigurator): try: logger.addHandler(self.config['handlers'][h]) except Exception as e: - raise ValueError('Unable to add handler %r: %s' % (h, e)) + raise ValueError('Unable to add handler %r' % h) from e def common_logger_config(self, logger, config, incremental=False): """ -- cgit v1.2.1 From 1cbeed1723de714ba73e719e1fddf4107be4a8a6 Mon Sep 17 00:00:00 2001 From: Vinay Sajip Date: Mon, 3 Oct 2016 19:50:56 +0100 Subject: Issue #28335: made minor improvement to implementation. --- Lib/logging/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Lib/logging/config.py') diff --git a/Lib/logging/config.py b/Lib/logging/config.py index 65d70daf5a..917178e511 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -559,7 +559,7 @@ class DictConfigurator(BaseConfigurator): handler.name = name handlers[name] = handler except Exception as e: - if 'Unable to set target handler' in str(e): + if 'target not configured yet' in str(e.__cause__): deferred.append(name) else: raise ValueError('Unable to configure handler ' -- cgit v1.2.1