From 5ef28bf804f18f732b5352ad34e10375de2beb5e Mon Sep 17 00:00:00 2001 From: "Ian H. Pittwood" Date: Tue, 24 Sep 2019 09:06:48 -0500 Subject: [PATCH] Change verbose option to granular verbosity Pegleg's current verbose option simply sets the logging level to either DEBUG or ERROR. This change allows users to enter a specific logging level anywhere between DEBUG and CRITICAL. The default logging level is set to 40=ERROR. The original verbose option will be kept in order to preserve backwards compatibility on existing scripts. Change-Id: I2cb81c55ab070380c4336ab8d75a9bf1c18b95fc --- pegleg/cli.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pegleg/cli.py b/pegleg/cli.py index 57a903fc..d23ecdf4 100644 --- a/pegleg/cli.py +++ b/pegleg/cli.py @@ -132,19 +132,30 @@ SITE_REPOSITORY_ARGUMENT = click.argument( is_flag=True, default=False, help='Enable debug logging') -def main(*, verbose): +@click.option( + '-l', + '--logging-level', + 'logging_level', + default='40', + show_default=True, + type=click.Choice(['10', '20', '30', '40', '50']), + help='Sets logging level where:\n' + '10=DEBUG\n' + '20=INFO\n' + '30=WARNING\n' + '40=ERROR\n' + '50=CRITICAL') +def main(*, verbose, logging_level): """Main CLI meta-group, which includes the following groups: * site: site-level actions * repo: repository-level actions """ - + lvl = logging_level if verbose: - log_level = logging.DEBUG - else: - log_level = logging.ERROR - logging.basicConfig(format=LOG_FORMAT, level=log_level) + lvl = logging.DEBUG + logging.basicConfig(format=LOG_FORMAT, level=int(lvl)) @main.group(help='Commands related to repositories')