12345678910111213141516171819202122232425 |
- # -*- coding: utf-8 -*-
- import os
- import time
- from loguru import logger
- # 日志文件配置
- # 本来是想 像flask那样把日志对象挂载到app对象上,作者建议直接使用全局对象
- # https://github.com/tiangolo/fastapi/issues/81#issuecomment-473677039
- # pip install loguru
- basedir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
- # print(f"log basedir{basedir}") # /xxx/python_code/FastAdmin/backend/app
- # 定位到log日志文件
- log_path = os.path.join(basedir, 'logs')
- if not os.path.exists(log_path):
- os.mkdir(log_path)
- log_path_error = os.path.join(log_path, f'{time.strftime("%Y-%m-%d")}_error.log')
- # 日志简单配置
- # 具体其他配置 可自行参考 https://github.com/Delgan/loguru
- logger.add(log_path_error, rotation="00:00", retention="365 days", enqueue=True)
|