From 04b85aa280dd510089424731a20e20f49c029c48 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 5 Jul 2021 23:54:25 -0400 Subject: [PATCH] Make log level configurable --- tutor/__main__.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tutor/__main__.py b/tutor/__main__.py index 46041c5..64301ed 100644 --- a/tutor/__main__.py +++ b/tutor/__main__.py @@ -68,10 +68,26 @@ class SearchHandler(tornado.web.RequestHandler): @click.group() @click.option("--database", type=click.Path(dir_okay=False), required=True) +@click.option( + "--log-level", + type=click.Choice( + ["debug", "info", "warn", "error"], + case_sensitive=False, + ), + default="warn", +) @click.pass_context -def cli(ctx, database): +def cli(ctx, database, log_level): + logging.basicConfig( + level={ + "debug": logging.DEBUG, + "info": logging.INFO, + "warn": logging.WARN, + "error": logging.ERROR, + }.get(log_level.lower()) + ) ctx.ensure_object(dict) - ctx.obj['database'] = database + ctx.obj["database"] = database @cli.command() @@ -97,5 +113,4 @@ def import_cards(ctx, filename): if __name__ == "__main__": - logging.basicConfig(level=logging.INFO) cli()