refactor code into modules

This commit is contained in:
Pim Nelissen
2026-01-31 09:42:21 +01:00
parent db6f859a60
commit 15b7e7e65e
8 changed files with 2 additions and 2 deletions

View File

@ -0,0 +1,21 @@
import logging
import logging.config
import pathlib
import yaml
def setup_logger(log_level: str = "WARNING"):
levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
if not log_level in levels:
raise ValueError(f"Log level must be one of {levels}.")
base_dir = pathlib.Path(__file__).resolve().parent
config_file = base_dir / "configs" / "logging.yml"
with open(config_file) as f:
config = yaml.safe_load(f)
config["loggers"]["root"]["level"] = log_level
logging.config.dictConfig(config)