mirror of
https://github.com/pim-n/pg-rad
synced 2026-02-02 14:33:09 +01:00
refactor code into modules
This commit is contained in:
21
src/pg_rad/logging/logger.py
Normal file
21
src/pg_rad/logging/logger.py
Normal 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)
|
||||
Reference in New Issue
Block a user