use getLevelNamesMapping() to get loglevel names

This commit is contained in:
onyx-and-iris 2026-02-09 01:49:49 +00:00
parent fb19a67e64
commit 7f3d47e7b0

View File

@ -30,13 +30,13 @@ def version_callback(value: bool):
def setup_logging(loglevel: str):
"""Set up logging for the application."""
loglevel = loglevel.upper()
if loglevel not in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']:
numeric_loglevel = logging.getLevelNamesMapping().get(loglevel.upper())
if numeric_loglevel is None:
raise typer.BadParameter(
f'Invalid log level: {loglevel}. Choose from DEBUG, INFO, WARNING, ERROR, CRITICAL.'
f'Invalid log level: {loglevel}. Valid options are: {", ".join(logging.getLevelNamesMapping().keys())}'
)
logging.basicConfig(
level=loglevel,
level=numeric_loglevel,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)