添加日志代码
This commit is contained in:
parent
60856736ee
commit
c613397ae5
5
app.py
5
app.py
|
|
@ -3,5 +3,6 @@
|
|||
# @Email :508737091@qq.com
|
||||
# @Author :qiangyanwen
|
||||
# @File :app.py
|
||||
from fastapi import Fastapi
|
||||
from router import
|
||||
from fastapi import FastAPI
|
||||
from router import routers
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
# -*- 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"]
|
||||
Loading…
Reference in New Issue