log_config.py 657 Bytes
import functools
import logging.config
import os
from typing import Any

import yaml


@functools.lru_cache()
def getLogConfig() -> dict[str, Any]:
    current_file_path = os.path.abspath(__file__)
    # 获取当前文件的上级目录
    parent_directory = os.path.dirname(current_file_path)
    # 构建application.yaml文件的路径
    application_yaml_path = os.path.join(parent_directory, '..', 'log-config.yaml')
    # 加载日志配置
    with open(application_yaml_path, 'r') as f:
        log_config = yaml.safe_load(f)
        return log_config


# 配置根日志记录器以供其他模块使用
logging.config.dictConfig(getLogConfig())