logging verbosity

This commit is contained in:
Jörn-Michael Miehe 2020-08-10 14:39:28 +02:00
parent 93643de8fb
commit 41274c3239
3 changed files with 21 additions and 16 deletions

View file

@ -5,12 +5,22 @@ import kiwi
from kiwi.subcommands import * from kiwi.subcommands import *
def main(): def set_verbosity(logger, handler, verbosity):
logging.basicConfig( if verbosity >= 2:
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", log_level = logging.DEBUG
level=logging.NOTSET log_format = "[%(asctime)s] %(levelname)s @ %(filename)s:%(funcName)s:%(lineno)d: %(message)s"
) elif verbosity >= 1:
log_level = logging.INFO
log_format = "[%(asctime)s] %(levelname)s: %(message)s"
else:
log_level = logging.WARNING
log_format = "%(levelname)s: %(message)s"
logger.setLevel(log_level)
handler.setFormatter(logging.Formatter(log_format))
def main():
commands = [ commands = [
InitCommand, InitCommand,
ShowCommand, ShowCommand,
@ -22,14 +32,10 @@ def main():
args = kiwi.Parser.get_args() args = kiwi.Parser.get_args()
if args.verbose >= 2: log_handler = logging.StreamHandler()
log_level = logging.DEBUG logging.getLogger().addHandler(log_handler)
elif args.verbose >= 1:
log_level = logging.INFO
else:
log_level = logging.WARNING
logging.getLogger().setLevel(log_level) set_verbosity(logging.getLogger(), log_handler, args.verbosity)
for cmd in commands: for cmd in commands:
if cmd.command == args.command: if cmd.command == args.command:

View file

@ -19,7 +19,7 @@ class Parser:
cls.__parser = argparse.ArgumentParser(description='kiwi-config') cls.__parser = argparse.ArgumentParser(description='kiwi-config')
cls.__parser.add_argument( cls.__parser.add_argument(
'-v', '--verbose', '-v', '--verbosity',
action='count', default=0 action='count', default=0
) )
@ -40,4 +40,3 @@ class Parser:
cls.__args = cls.get_parser().parse_args() cls.__args = cls.get_parser().parse_args()
return cls.__args return cls.__args

View file

@ -37,11 +37,11 @@ def user_input_exe(config, key):
program_name = key.split(':')[1] program_name = key.split(':')[1]
if not is_executable(exe_file): if not is_executable(exe_file):
logging.warning("Reconfiguring '%s' executable path.", program_name) logging.info("Reconfiguring '%s' executable path.", program_name)
exe_file = find_exe(program_name) exe_file = find_exe(program_name)
if exe_file is not None: if exe_file is not None:
logging.info("Found executable at '%s'.", exe_file) logging.debug("Found executable at '%s'.", exe_file)
config[key] = exe_file config[key] = exe_file
else: else:
user_input(config, key, f"Enter path to '{program_name}' executable") user_input(config, key, f"Enter path to '{program_name}' executable")