INNER CODE UNIT · Python

find_and_load_logging_conf

br3ndonland/inboard · inboard/logging_conf.py:15

def find_and_load_logging_conf(logging_conf: str) -> DictConfig:
    """Find and load a logging configuration module or file."""
    logging_conf_path = Path(logging_conf)
    spec = (
        importlib.util.spec_from_file_location("confspec", logging_conf_path)
        if logging_conf_path.is_file() and logging_conf_path.suffix == ".py"
        else importlib.util.find_spec(logging_conf)
    )
    if not spec:
        raise ImportError(f"Unable to import {logging_conf_path}")
    logging_conf_module = importlib.util.module_from_spec(spec)
    exec_module = spec.loader.exec_module  # pyright: ignore[reportOptionalMemberAccess]
    exec_module(logging_conf_module)
    if not hasattr(logging_conf_module, "LOGGING_CONFIG"):
        raise AttributeError(f"No LOGGING_CONFIG in {logging_conf_module.__name__}")
    logging_conf_dict = logging_conf_module.LOGGING_CONFIG  # pyright: ignore[reportAny]
    if not isinstance(logging_conf_dict, dict):
        raise TypeError("LOGGING_CONFIG is not a dictionary instance")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…