Make log level configurable

This commit is contained in:
Correl Roush 2021-07-05 23:54:25 -04:00
parent 4c0fdbe89f
commit 04b85aa280

View file

@ -68,10 +68,26 @@ class SearchHandler(tornado.web.RequestHandler):
@click.group() @click.group()
@click.option("--database", type=click.Path(dir_okay=False), required=True) @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 @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.ensure_object(dict)
ctx.obj['database'] = database ctx.obj["database"] = database
@cli.command() @cli.command()
@ -97,5 +113,4 @@ def import_cards(ctx, filename):
if __name__ == "__main__": if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
cli() cli()