1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-25 18:42:59 +00:00

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 *
def main():
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.NOTSET
)
def set_verbosity(logger, handler, verbosity):
if verbosity >= 2:
log_level = logging.DEBUG
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 = [
InitCommand,
ShowCommand,
@ -22,14 +32,10 @@ def main():
args = kiwi.Parser.get_args()
if args.verbose >= 2:
log_level = logging.DEBUG
elif args.verbose >= 1:
log_level = logging.INFO
else:
log_level = logging.WARNING
log_handler = logging.StreamHandler()
logging.getLogger().addHandler(log_handler)
logging.getLogger().setLevel(log_level)
set_verbosity(logging.getLogger(), log_handler, args.verbosity)
for cmd in commands:
if cmd.command == args.command:

View file

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

View file

@ -37,11 +37,11 @@ def user_input_exe(config, key):
program_name = key.split(':')[1]
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)
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
else:
user_input(config, key, f"Enter path to '{program_name}' executable")