Add -l/--log-level option. Honor __cdist_loglevel env var. (#572)
Add -l/--log-level option, __cdist_loglevel -> __cdist_log_level; honor __cdist_log_level env var
This commit is contained in:
parent
f08ac264a0
commit
3454da076f
23 changed files with 152 additions and 69 deletions
|
|
@ -3,6 +3,7 @@ import cdist
|
|||
import multiprocessing
|
||||
import logging
|
||||
import collections
|
||||
import functools
|
||||
import cdist.configuration
|
||||
|
||||
|
||||
|
|
@ -72,15 +73,15 @@ def check_beta(args_dict):
|
|||
raise cdist.CdistBetaRequired(cmd, arg)
|
||||
|
||||
|
||||
def check_positive_int(value):
|
||||
def check_lower_bounded_int(value, lower_bound, name):
|
||||
try:
|
||||
val = int(value)
|
||||
except ValueError:
|
||||
raise argparse.ArgumentTypeError(
|
||||
"{} is invalid int value".format(value))
|
||||
if val <= 0:
|
||||
if val < lower_bound:
|
||||
raise argparse.ArgumentTypeError(
|
||||
"{} is invalid positive int value".format(val))
|
||||
"{} is invalid {} value".format(val, name))
|
||||
return val
|
||||
|
||||
|
||||
|
|
@ -94,6 +95,17 @@ def get_parsers():
|
|||
parser = {}
|
||||
# Options _all_ parsers have in common
|
||||
parser['loglevel'] = argparse.ArgumentParser(add_help=False)
|
||||
parser['loglevel'].add_argument(
|
||||
'-l', '--log-level', metavar='LOGLEVEL',
|
||||
type=functools.partial(check_lower_bounded_int, lower_bound=-1,
|
||||
name="log level"),
|
||||
help=('Set the specified verbosity level. '
|
||||
'The levels, in order from the lowest to the highest, are: '
|
||||
'ERROR (-1), WARNING (0), INFO (1), VERBOSE (2), DEBUG (3) '
|
||||
'TRACE (4 or higher). If used along with -v then -v '
|
||||
'increases last set value and -l overwrites last set '
|
||||
'value.'),
|
||||
action='store', dest='verbose', required=False)
|
||||
parser['loglevel'].add_argument(
|
||||
'-q', '--quiet',
|
||||
help='Quiet mode: disables logging, including WARNING and ERROR.',
|
||||
|
|
@ -105,7 +117,9 @@ def get_parsers():
|
|||
'is 0 which includes ERROR and WARNING levels. '
|
||||
'The levels, in order from the lowest to the highest, are: '
|
||||
'ERROR (-1), WARNING (0), INFO (1), VERBOSE (2), DEBUG (3) '
|
||||
'TRACE (4 or higher).'),
|
||||
'TRACE (4 or higher). If used along with -l then -l '
|
||||
'overwrites last set value and -v increases last set '
|
||||
'value.'),
|
||||
action='count', default=None)
|
||||
|
||||
parser['beta'] = argparse.ArgumentParser(add_help=False)
|
||||
|
|
@ -164,7 +178,8 @@ def get_parsers():
|
|||
dest='manifest', required=False)
|
||||
parser['config_main'].add_argument(
|
||||
'-j', '--jobs', nargs='?',
|
||||
type=check_positive_int,
|
||||
type=functools.partial(check_lower_bounded_int, lower_bound=1,
|
||||
name="positive int"),
|
||||
help=('Operate in parallel in specified maximum number of jobs. '
|
||||
'Global explorers, object prepare and object run are '
|
||||
'supported. Without argument CPU count is used by default. '
|
||||
|
|
@ -229,7 +244,8 @@ def get_parsers():
|
|||
dest='hostfile', required=False)
|
||||
parser['config_args'].add_argument(
|
||||
'-p', '--parallel', nargs='?', metavar='HOST_MAX',
|
||||
type=check_positive_int,
|
||||
type=functools.partial(check_lower_bounded_int, lower_bound=1,
|
||||
name="positive int"),
|
||||
help=('Operate on multiple hosts in parallel for specified maximum '
|
||||
'hosts at a time. Without argument CPU count is used by '
|
||||
'default.'),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue