monitoring/config/log.py

27 lines
1.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name log.py
Description :
Author : qiangyanwen
date 2022/1/14
-------------------------------------------------
"""
import os
from loguru import logger
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
log_path = os.path.join(basedir, 'logs')
if not os.path.exists(log_path):
os.mkdir(log_path)
format_str = '{time:YYYY-MM-DD HH:mm:ss} | {thread.name}:{thread.id} | {function}:{module}:{line} - {level} - {message}'
log_path_info = os.path.join(log_path, 'automation_info.log')
log_path_error = os.path.join(log_path, 'automation_error.log')
# 日志简单配置 文件区分不同级别的日志
logger.add(log_path_info, format=format_str, rotation="00:00", retention="15 days", encoding='utf-8', enqueue=True, level='INFO')
logger.add(log_path_error, format=format_str, rotation="00:00", retention="15 days", encoding='utf-8', enqueue=True, level='ERROR')
__all__ = ["logger"]