[Python-checkins] cpython: Closes #28335: used 'raise from' in logging configuration code.

vinay.sajip python-checkins at python.org
Mon Oct 3 14:46:14 EDT 2016


https://hg.python.org/cpython/rev/69bf09bf4952
changeset:   104268:69bf09bf4952
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Mon Oct 03 19:45:50 2016 +0100
summary:
  Closes #28335: used 'raise from' in logging configuration code.

files:
  Lib/logging/config.py |  32 +++++++++++++++---------------
  1 files changed, 16 insertions(+), 16 deletions(-)


diff --git a/Lib/logging/config.py b/Lib/logging/config.py
--- 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 @@
 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 @@
                                 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 @@
                                                             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 @@
                         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 @@
                         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 @@
                         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 @@
                         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 @@
                         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 @@
             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 @@
                 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 @@
                     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 @@
             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):
         """

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


More information about the Python-checkins mailing list