Allow verbosity to be converted to log level and then use log level from then on out
This commit is contained in:
parent
c1b39af1ef
commit
22fda3da93
@ -74,13 +74,17 @@ COWS['unhappy'] = r'''
|
||||
'''
|
||||
|
||||
|
||||
def configure_logging(verbosity_level=1, dry_run=False):
|
||||
def construct_log_level(verbosity_level, dry_run=False):
|
||||
log_level = logging.INFO
|
||||
if verbosity_level >= 3:
|
||||
log_level = logging.DEBUG
|
||||
elif verbosity_level == 2 or dry_run:
|
||||
log_level = logging.AUDIT
|
||||
return log_level
|
||||
|
||||
# Debug by default
|
||||
|
||||
def configure_logging(log_level):
|
||||
root_logger = logging.getLogger().logger
|
||||
root_logger.setLevel(logging.DEBUG)
|
||||
|
||||
# Set our pretty logger
|
||||
console_logger = logging.StreamHandler(sys.stdout)
|
||||
console_format = '%(levelname)s: @%(name)s : %(message)s'
|
||||
if sh.in_terminal():
|
||||
@ -88,13 +92,6 @@ def configure_logging(verbosity_level=1, dry_run=False):
|
||||
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 >= 3:
|
||||
log_level = logging.DEBUG
|
||||
elif verbosity_level == 2 or dry_run:
|
||||
log_level = logging.AUDIT
|
||||
root_logger.setLevel(log_level)
|
||||
|
||||
|
||||
|
7
stack
7
stack
@ -179,10 +179,11 @@ def main():
|
||||
prog_name = sys.argv[0]
|
||||
|
||||
# Configure logging
|
||||
verbosity = args['verbosity']
|
||||
utils.configure_logging(verbosity, args['dryrun'])
|
||||
log_level = utils.construct_log_level(args['verbosity'], args['dryrun'])
|
||||
utils.configure_logging(log_level)
|
||||
|
||||
LOG.debug("Command line options %s" % (args))
|
||||
LOG.debug("Log level is: %s" % (log_level))
|
||||
|
||||
# Will need root to setup openstack
|
||||
if not sh.got_root():
|
||||
@ -208,7 +209,7 @@ def main():
|
||||
except Exception:
|
||||
utils.goodbye(False)
|
||||
traceback = None
|
||||
if verbosity >= 3:
|
||||
if log_level <= logging.DEBUG:
|
||||
# See: http://docs.python.org/library/traceback.html
|
||||
traceback = sys.exc_traceback
|
||||
tb.print_exception(sys.exc_type, sys.exc_value,
|
||||
|
@ -31,7 +31,7 @@ if __name__ == "__main__":
|
||||
(options, args) = parser.parse_args()
|
||||
uris = options.uris or list()
|
||||
uri_sep = ",".join(uris)
|
||||
utils.configure_logging(3)
|
||||
utils.configure_logging(logging.DEBUG)
|
||||
config = cfg.StackConfigParser()
|
||||
config.add_section('img')
|
||||
config.set('img', 'image_urls', uri_sep)
|
||||
|
Loading…
x
Reference in New Issue
Block a user