kas: add support for --log-level argument

KAS by default will output a lot of information (INFO) messages for
all operations, which makes it difficult to spot warnings thru all
that 'noise'.

Add a command line argument so that the default log level can be
modified.

For backward compatibility, the --debug parameter is still supported
but marked as deprecated in the help message.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
[Jan: style fixes]
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Hugo Villeneuve 2023-05-03 16:53:37 +02:00 committed by Jan Kiszka
parent 246f23cbca
commit 522a2422c4

View File

@ -118,8 +118,15 @@ def kas_get_argparser():
parser.add_argument('--version', action='version', version=verstr)
parser.add_argument('-d', '--debug',
action='store_true',
help='Enable debug logging')
action='store_const', const='debug', dest='log_level',
help='Enable debug logging (deprecated, use '
'--log-level debug).')
parser.add_argument('-l', '--log-level',
choices=['debug', 'info', 'warning', 'error',
'critical'],
default='%s' % (default_log_level),
help='Set log level (default: %s)' % default_log_level)
subparser = parser.add_subparsers(help='sub command help', dest='cmd')
@ -139,8 +146,9 @@ def kas(argv):
parser = kas_get_argparser()
args = parser.parse_args(argv)
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
if args.log_level:
level_num = logging.getLevelName(args.log_level.upper())
logging.getLogger().setLevel(level_num)
logging.info('%s %s started', os.path.basename(sys.argv[0]), __version__)