From 67354f651b064c7c67ad749bf75196d59b851d18 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Wed, 7 May 2014 10:54:38 -0500 Subject: [PATCH] Clean up logging levels The following logging levels are set according to the combination of --verbose, --quiet and --debug options: verbose_level logging level options 0 --quiet ERROR 1 (none) WARNING 2 --verbose INFO 3+ --verbose --verbose DEBUG or --debug Logging levels for the requests and iso8601 modules are forced to ERROR. This is the first step in bp use-logging-not-print The difference between '--debug' and '--verbose --verbose' is --debug triggers cliff's exception handling and traceback display. Change-Id: Ide2233b3316471d279260fb1e7255a6ca2072023 --- openstackclient/common/commandmanager.py | 1 - openstackclient/shell.py | 53 ++++++++++++++++++++---- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/openstackclient/common/commandmanager.py b/openstackclient/common/commandmanager.py index 204b943bcf..aa238a23f0 100644 --- a/openstackclient/common/commandmanager.py +++ b/openstackclient/common/commandmanager.py @@ -37,7 +37,6 @@ class CommandManager(cliff.commandmanager.CommandManager): group = self.namespace self.group_list.append(group) for ep in pkg_resources.iter_entry_points(group): - LOG.debug('found command %r', ep.name) cmd_name = ( ep.name.replace('_', ' ') if self.convert_underscores diff --git a/openstackclient/shell.py b/openstackclient/shell.py index 719ee4803b..67eaca55e6 100644 --- a/openstackclient/shell.py +++ b/openstackclient/shell.py @@ -123,6 +123,50 @@ class OpenStackShell(app.App): help="Show this help message and exit", ) + def configure_logging(self): + """Configure logging for the app + + Cliff sets some defaults we don't want so re-work it a bit + """ + + if self.options.debug: + # --debug forces verbose_level 3 + # Set this here so cliff.app.configure_logging() can work + self.options.verbose_level = 3 + + super(OpenStackShell, self).configure_logging() + root_logger = logging.getLogger('') + + # Requests logs some stuff at INFO that we don't want + # unless we have DEBUG + requests_log = logging.getLogger("requests") + requests_log.setLevel(logging.ERROR) + + # Other modules we don't want DEBUG output for so + # don't reset them below + iso8601_log = logging.getLogger("iso8601") + iso8601_log.setLevel(logging.ERROR) + + # Set logging to the requested level + self.dump_stack_trace = False + if self.options.verbose_level == 0: + # --quiet + root_logger.setLevel(logging.ERROR) + elif self.options.verbose_level == 1: + # This is the default case, no --debug, --verbose or --quiet + root_logger.setLevel(logging.WARNING) + elif self.options.verbose_level == 2: + # One --verbose + root_logger.setLevel(logging.INFO) + elif self.options.verbose_level >= 3: + # Two or more --verbose + root_logger.setLevel(logging.DEBUG) + requests_log.setLevel(logging.DEBUG) + + if self.options.debug: + # --debug forces traceback + self.dump_stack_trace = True + def run(self, argv): try: return super(OpenStackShell, self).run(argv) @@ -401,15 +445,6 @@ class OpenStackShell(app.App): super(OpenStackShell, self).initialize_app(argv) - # Set requests logging to a useful level - requests_log = logging.getLogger("requests") - if self.options.debug: - requests_log.setLevel(logging.DEBUG) - self.dump_stack_trace = True - else: - requests_log.setLevel(logging.WARNING) - self.dump_stack_trace = False - # Save default domain self.default_domain = self.options.os_default_domain