|
1234567891011121314151617181920212223242526272829 |
- # -*- coding: utf-8 -*-
- import sys
- from os import makedirs
- from os.path import join, exists
- from loguru import logger
- from util.RWUtils import getConfigs
-
-
- # 初始化日志配置
- def init_log(base_dir):
- log_config = getConfigs(base_dir, 'config/logger.yml')
- # 判断日志文件是否存在,不存在创建
- base_path = join(base_dir, log_config["base_path"])
- if not exists(base_path):
- makedirs(base_path)
- # 移除日志设置
- logger.remove(handler_id=None)
- # 打印日志到文件
- if bool(log_config["enable_file_log"]):
- logger.add(join(base_path, log_config["log_name"]),
- rotation=log_config["rotation"],
- retention=log_config["retention"],
- format=log_config["log_fmt"],
- level=log_config["level"],
- enqueue=True,
- encoding=log_config["encoding"])
- # 控制台输出
- if bool(log_config["enable_stderr"]):
- logger.add(sys.stderr, format=log_config["log_fmt"], level=log_config["level"], enqueue=True)
|