Browse files

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
  • Loading branch information...
1 parent c5b5799 commit e9e05d7dfe6809adc009f79ca3ee08a332488094 @alvarolopez alvarolopez committed Mar 13, 2013
Showing with 12 additions and 6 deletions.
  1. +8 −2 novaclient/client.py
  2. +4 −4 novaclient/shell.py
View
10 novaclient/client.py
@@ -97,11 +97,17 @@ def __init__(self, user, password, projectid, auth_url=None,
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
View
8 novaclient/shell.py
@@ -507,11 +507,11 @@ def setup_debugging(self, debug):
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

0 comments on commit e9e05d7

Please sign in to comment.