Moved logging initial configuring to utils, so that other tools programs can use it if they want

This commit is contained in:
Joshua Harlow 2012-03-13 12:54:33 -07:00
parent 41f09bb044
commit bdcca74d74
2 changed files with 26 additions and 26 deletions

View File

@ -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)

27
stack
View File

@ -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))