From 4ec5022e4ba9ef577c2cb6ad32f26c9cfcb1fbb9 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Tue, 12 Jul 2016 08:33:18 -0400 Subject: [PATCH] make error reporting for extension loading quieter Only log the full traceback for an import error from an extension if debug logging is enabled. This avoids spurious tracebacks in the log when an application probes for all available extensions or when a dependency of an extension is not installed (in that case the error message itself should be sufficient to debug the issue). Change-Id: I43c24f3791d575c2ecf0d08d82d9de5d74ec1150 Signed-off-by: Doug Hellmann --- stevedore/extension.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/stevedore/extension.py b/stevedore/extension.py index d240988..aa14e0a 100644 --- a/stevedore/extension.py +++ b/stevedore/extension.py @@ -170,8 +170,15 @@ class ExtensionManager(object): if self._on_load_failure_callback is not None: self._on_load_failure_callback(self, ep, err) else: - LOG.error('Could not load %r: %s', ep.name, err) - LOG.exception(err) + # Log the reason we couldn't import the module, + # usually without a traceback. The most common + # reason is an ImportError due to a missing + # dependency, and the error message should be + # enough to debug that. If debug logging is + # enabled for our logger, provide the full + # traceback. + LOG.error('Could not load %r: %s', ep.name, err, + exc_info=LOG.isEnabledFor(logging.DEBUG)) return extensions def _load_one_plugin(self, ep, invoke_on_load, invoke_args, invoke_kwds,