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. The log level is set using
the "log-level" option and the output file using "log-file." These
should match similar options in the lsst/daf_butler repo.
  • Loading branch information
JeremyMcCormick committed Mar 1, 2024
1 parent 832e8e1 commit ebd4d21
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(
"--log-level",
type=click.Choice(loglevel_choices),
envvar="FELIS_LOGLEVEL",
help="Felis log level",
default=logging.getLevelName(logging.INFO),
)
@click.option(
"--log-file",
type=click.Path(),
envvar="FELIS_LOGFILE",
help="Felis log file path",
)
def cli(log_level: str, log_file: str | None) -> None:
"""Felis Command Line Tools."""
logging.basicConfig(level=logging.INFO)
if log_file:
logging.basicConfig(filename=log_file, level=log_level)

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=log_level)


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

0 comments on commit ebd4d21

Please sign in to comment.