Closes #28335: used 'raise from' in logging configuration code.
This commit is contained in:
parent
cc30fc72c6
commit
aa27582f35
|
@ -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
|
# Permission to use, copy, modify, and distribute this software and its
|
||||||
# documentation for any purpose and without fee is hereby granted,
|
# 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
|
is based on PEP 282 and comments thereto in comp.lang.python, and influenced
|
||||||
by Apache's log4j system.
|
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!
|
To use, simply 'import logging' and log away!
|
||||||
"""
|
"""
|
||||||
|
@ -509,21 +509,21 @@ class DictConfigurator(BaseConfigurator):
|
||||||
handler.setLevel(logging._checkLevel(level))
|
handler.setLevel(logging._checkLevel(level))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure handler '
|
raise ValueError('Unable to configure handler '
|
||||||
'%r: %s' % (name, e))
|
'%r' % name) from e
|
||||||
loggers = config.get('loggers', EMPTY_DICT)
|
loggers = config.get('loggers', EMPTY_DICT)
|
||||||
for name in loggers:
|
for name in loggers:
|
||||||
try:
|
try:
|
||||||
self.configure_logger(name, loggers[name], True)
|
self.configure_logger(name, loggers[name], True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure logger '
|
raise ValueError('Unable to configure logger '
|
||||||
'%r: %s' % (name, e))
|
'%r' % name) from e
|
||||||
root = config.get('root', None)
|
root = config.get('root', None)
|
||||||
if root:
|
if root:
|
||||||
try:
|
try:
|
||||||
self.configure_root(root, True)
|
self.configure_root(root, True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure root '
|
raise ValueError('Unable to configure root '
|
||||||
'logger: %s' % e)
|
'logger') from e
|
||||||
else:
|
else:
|
||||||
disable_existing = config.pop('disable_existing_loggers', True)
|
disable_existing = config.pop('disable_existing_loggers', True)
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
formatters[name])
|
formatters[name])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure '
|
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
|
# Next, do filters - they don't refer to anything else, either
|
||||||
filters = config.get('filters', EMPTY_DICT)
|
filters = config.get('filters', EMPTY_DICT)
|
||||||
for name in filters:
|
for name in filters:
|
||||||
|
@ -546,7 +546,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
filters[name] = self.configure_filter(filters[name])
|
filters[name] = self.configure_filter(filters[name])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure '
|
raise ValueError('Unable to configure '
|
||||||
'filter %r: %s' % (name, e))
|
'filter %r' % name) from e
|
||||||
|
|
||||||
# Next, do handlers - they refer to formatters and filters
|
# Next, do handlers - they refer to formatters and filters
|
||||||
# As handlers can refer to other handlers, sort the keys
|
# As handlers can refer to other handlers, sort the keys
|
||||||
|
@ -559,11 +559,11 @@ class DictConfigurator(BaseConfigurator):
|
||||||
handler.name = name
|
handler.name = name
|
||||||
handlers[name] = handler
|
handlers[name] = handler
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if 'target not configured yet' in str(e):
|
if 'Unable to set target handler' in str(e):
|
||||||
deferred.append(name)
|
deferred.append(name)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unable to configure handler '
|
raise ValueError('Unable to configure handler '
|
||||||
'%r: %s' % (name, e))
|
'%r' % name) from e
|
||||||
|
|
||||||
# Now do any that were deferred
|
# Now do any that were deferred
|
||||||
for name in deferred:
|
for name in deferred:
|
||||||
|
@ -573,7 +573,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
handlers[name] = handler
|
handlers[name] = handler
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure handler '
|
raise ValueError('Unable to configure handler '
|
||||||
'%r: %s' % (name, e))
|
'%r' % name) from e
|
||||||
|
|
||||||
# Next, do loggers - they refer to handlers and filters
|
# Next, do loggers - they refer to handlers and filters
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
self.configure_logger(name, loggers[name])
|
self.configure_logger(name, loggers[name])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure logger '
|
raise ValueError('Unable to configure logger '
|
||||||
'%r: %s' % (name, e))
|
'%r' % name) from e
|
||||||
|
|
||||||
#Disable any old loggers. There's no point deleting
|
#Disable any old loggers. There's no point deleting
|
||||||
#them as other threads may continue to hold references
|
#them as other threads may continue to hold references
|
||||||
|
@ -637,7 +637,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
self.configure_root(root)
|
self.configure_root(root)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to configure root '
|
raise ValueError('Unable to configure root '
|
||||||
'logger: %s' % e)
|
'logger') from e
|
||||||
finally:
|
finally:
|
||||||
logging._releaseLock()
|
logging._releaseLock()
|
||||||
|
|
||||||
|
@ -684,7 +684,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
try:
|
try:
|
||||||
filterer.addFilter(self.config['filters'][f])
|
filterer.addFilter(self.config['filters'][f])
|
||||||
except Exception as e:
|
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):
|
def configure_handler(self, config):
|
||||||
"""Configure a handler from a dictionary."""
|
"""Configure a handler from a dictionary."""
|
||||||
|
@ -695,7 +695,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
formatter = self.config['formatters'][formatter]
|
formatter = self.config['formatters'][formatter]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to set formatter '
|
raise ValueError('Unable to set formatter '
|
||||||
'%r: %s' % (formatter, e))
|
'%r' % formatter) from e
|
||||||
level = config.pop('level', None)
|
level = config.pop('level', None)
|
||||||
filters = config.pop('filters', None)
|
filters = config.pop('filters', None)
|
||||||
if '()' in config:
|
if '()' in config:
|
||||||
|
@ -717,7 +717,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
config['target'] = th
|
config['target'] = th
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError('Unable to set target handler '
|
raise ValueError('Unable to set target handler '
|
||||||
'%r: %s' % (config['target'], e))
|
'%r' % config['target']) from e
|
||||||
elif issubclass(klass, logging.handlers.SMTPHandler) and\
|
elif issubclass(klass, logging.handlers.SMTPHandler) and\
|
||||||
'mailhost' in config:
|
'mailhost' in config:
|
||||||
config['mailhost'] = self.as_tuple(config['mailhost'])
|
config['mailhost'] = self.as_tuple(config['mailhost'])
|
||||||
|
@ -755,7 +755,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
try:
|
try:
|
||||||
logger.addHandler(self.config['handlers'][h])
|
logger.addHandler(self.config['handlers'][h])
|
||||||
except Exception as e:
|
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):
|
def common_logger_config(self, logger, config, incremental=False):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue