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()