Skip to content

Commit

Permalink
Add command line options for setting log level and file
Browse files Browse the repository at this point in the history
Two command line options are added for setting the Felis log level and,
optionally, an output file for log messages.
  • Loading branch information
JeremyMcCormick committed Feb 27, 2024
1 parent 832e8e1 commit 5bf1c58
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions python/felis/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,30 @@

logger = logging.getLogger("felis")

loglevel_choices = ["CRITICAL", "FATAL", "ERROR", "WARNING", "INFO", "DEBUG"]


@click.group()
@click.version_option(__version__)
def cli() -> None:
@click.option(
"--loglevel",
type=click.Choice(loglevel_choices),
envvar="FELIS_LOGLEVEL",
help="Felis log level",
default=logging.getLevelName(logging.INFO),
)
@click.option(
"--logfile",
type=click.Path(),
envvar="FELIS_LOGFILE",
help="Felis log file path",
)
def cli(loglevel: str, logfile: str | None) -> None:
"""Felis Command Line Tools."""
logging.basicConfig(level=logging.INFO)
if logfile:
logging.basicConfig(filename=logfile, level=loglevel)

Check warning on line 69 in python/felis/cli.py

View check run for this annotation

Codecov / codecov/patch

python/felis/cli.py#L69

Added line #L69 was not covered by tests
else:
logging.basicConfig(level=loglevel)


@cli.command("create-all")
Expand Down

0 comments on commit 5bf1c58

Please sign in to comment.