From bdcca74d746df8a947faef0e949ac1c3d31f8de6 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 13 Mar 2012 12:54:33 -0700 Subject: [PATCH] Moved logging initial configuring to utils, so that other tools programs can use it if they want --- devstack/utils.py | 25 +++++++++++++++++++++++++ stack | 27 +-------------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/devstack/utils.py b/devstack/utils.py index 7e4aade0..45fb66b8 100644 --- a/devstack/utils.py +++ b/devstack/utils.py @@ -28,6 +28,7 @@ import socket import sys import termcolor +from devstack import colorlog from devstack import exceptions as excp from devstack import log as logging from devstack import settings @@ -70,6 +71,30 @@ COWS['unhappy'] = r''' ''' +def configure_logging(verbosity_level=1, dry_run=False): + + # Debug by default + root_logger = logging.getLogger().logger + root_logger.setLevel(logging.DEBUG) + + # Set our pretty logger + console_logger = logging.StreamHandler(stream=sys.stdout) + console_format = '%(levelname)s: @%(name)s : %(message)s' + if sh.in_terminal(): + console_logger.setFormatter(colorlog.TermFormatter(console_format)) + else: + console_logger.setFormatter(logging.Formatter(console_format)) + root_logger.addHandler(console_logger) + + # Adjust logging verbose level based on the command line switch. + log_level = logging.INFO + if verbosity_level >= 2: + log_level = logging.DEBUG + elif dry_run: + log_level = logging.AUDIT + root_logger.setLevel(log_level) + + def load_template(component, template_name): full_pth = sh.joinpths(settings.STACK_TEMPLATE_DIR, component, template_name) contents = sh.load_file(full_pth) diff --git a/stack b/stack index 1bc0fef0..c3ea7639 100755 --- a/stack +++ b/stack @@ -21,7 +21,6 @@ import time import traceback from devstack import cfg_helpers -from devstack import colorlog from devstack import date from devstack import log as logging from devstack import opts @@ -130,30 +129,6 @@ def run(args): return True -def configure_logging(args): - - # Debug by default - root_logger = logging.getLogger().logger - root_logger.setLevel(logging.DEBUG) - - # Set our pretty logger - console_logger = logging.StreamHandler(stream=sys.stdout) - console_format = '%(levelname)s: @%(name)s : %(message)s' - if sh.in_terminal(): - console_logger.setFormatter(colorlog.TermFormatter(console_format)) - else: - console_logger.setFormatter(logging.Formatter(console_format)) - root_logger.addHandler(console_logger) - - # Adjust logging verbose level based on the command line switch. - log_level = logging.INFO - if args['verbosity'] >= 2: - log_level = logging.DEBUG - elif args['dryrun']: - log_level = logging.AUDIT - root_logger.setLevel(log_level) - - def main(): #do this first so people can see the help message... @@ -161,7 +136,7 @@ def main(): prog_name = sys.argv[0] # Configure logging - configure_logging(args) + utils.configure_logging(args['verbosity'], args['dryrun']) LOG.debug("Command line options %s" % (args))