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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# !/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 " ]