You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
843 B

3 years ago
# !/usr/bin/env python3
# -*- encoding : utf-8 -*-
# @Filename : logger.py
# @Software : VSCode
# @Datetime : 2021/11/03 17:17:17
# @Author : leo liu
# @Version : 1.0
# @Description :
"""
日志文件配置
# 本来是想 像flask那样把日志对象挂载到app对象上作者建议直接使用全局对象
https://github.com/tiangolo/fastapi/issues/81#issuecomment-473677039
"""
import os
import time
from loguru import logger
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# 定位到log日志文件
log_path = os.path.join(basedir, 'logs')
if not os.path.exists(log_path):
os.mkdir(log_path)
log_path = os.path.join(log_path, f'{time.strftime("%Y-%m-%d")}.log')
# 日志简单配置
logger.add(log_path, rotation="12:00", retention="5 days", enqueue=True)
__all__ = ["logger"]