mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-11 19:58:11 +01:00
22 lines
522 B
Python
22 lines
522 B
Python
import logging
|
|
import pathlib
|
|
|
|
import yaml
|
|
|
|
|
|
def setup_logger(log_level: str = "WARNING"):
|
|
levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
|
|
if log_level not 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)
|