mirror of
https://github.com/pim-n/pg-rad
synced 2026-03-23 21:58:12 +01:00
rename pg_rad logging->logger to avoid import conflict with default logging library.
This commit is contained in:
22
src/pg_rad/logger/logger.py
Normal file
22
src/pg_rad/logger/logger.py
Normal file
@ -0,0 +1,22 @@
|
||||
import logging.config
|
||||
from importlib.resources import files
|
||||
|
||||
import yaml
|
||||
|
||||
from pg_rad.configs.filepaths import LOGGING_CONFIG
|
||||
|
||||
|
||||
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}.")
|
||||
|
||||
config_file = files('pg_rad.configs').joinpath(LOGGING_CONFIG)
|
||||
|
||||
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