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:
parent
246f23cbca
commit
522a2422c4
16
kas/kas.py
16
kas/kas.py
@ -118,8 +118,15 @@ def kas_get_argparser():
|
|||||||
parser.add_argument('--version', action='version', version=verstr)
|
parser.add_argument('--version', action='version', version=verstr)
|
||||||
|
|
||||||
parser.add_argument('-d', '--debug',
|
parser.add_argument('-d', '--debug',
|
||||||
action='store_true',
|
action='store_const', const='debug', dest='log_level',
|
||||||
help='Enable debug logging')
|
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')
|
subparser = parser.add_subparsers(help='sub command help', dest='cmd')
|
||||||
|
|
||||||
@ -139,8 +146,9 @@ def kas(argv):
|
|||||||
parser = kas_get_argparser()
|
parser = kas_get_argparser()
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
if args.debug:
|
if args.log_level:
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
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__)
|
logging.info('%s %s started', os.path.basename(sys.argv[0]), __version__)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user