From e9e05d7dfe6809adc009f79ca3ee08a332488094 Mon Sep 17 00:00:00 2001 From: Alvaro Lopez Garcia Date: Wed, 13 Mar 2013 16:47:16 +0100 Subject: [PATCH] Set up debug level on root logger. If we set up the debug level on the root logger, this can be used by the submodules that might need to print some debug output. Change-Id: I2a00b40d4748cc62e6081df7d6a44622f5ad4467 --- novaclient/client.py | 10 ++++++++-- novaclient/shell.py | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/novaclient/client.py b/novaclient/client.py index e49aa4c80..73595701c 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -97,11 +97,17 @@ class HTTPClient(object): self._logger = logging.getLogger(__name__) if self.http_log_debug: + # Logging level is already set on the root logger ch = logging.StreamHandler() - self._logger.setLevel(logging.DEBUG) self._logger.addHandler(ch) + self._logger.propagate = False if hasattr(requests, 'logging'): - requests.logging.getLogger(requests.__name__).addHandler(ch) + rql = requests.logging.getLogger(requests.__name__) + rql.addHandler(ch) + # Since we have already setup the root logger on debug, we + # have to set it up here on WARNING (its original level) + # otherwise we will get all the requests logging messanges + rql.setLevel(logging.WARNING) def use_token_cache(self, use_it): self.os_cache = use_it diff --git a/novaclient/shell.py b/novaclient/shell.py index bf56b0fdb..8b4aea512 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -507,11 +507,11 @@ class OpenStackComputeShell(object): if not debug: return - streamhandler = logging.StreamHandler() streamformat = "%(levelname)s (%(module)s:%(lineno)d) %(message)s" - streamhandler.setFormatter(logging.Formatter(streamformat)) - logger.setLevel(logging.DEBUG) - logger.addHandler(streamhandler) + # Set up the root logger to debug so that the submodules can + # print debug messages + logging.basicConfig(level=logging.DEBUG, + format=streamformat) def main(self, argv): # Parse args once to find version and debug settings