tfse-admin-api-v0.2/Log/log_utils.py

46 lines
1.1 KiB
Python
Raw Normal View History

2022-03-31 03:57:36 +08:00
import time
from flask import request
2022-03-30 16:47:27 +08:00
import functools
2022-03-31 03:57:36 +08:00
import traceback
from DBHelper.MongoHelper import MongoHelper
2022-03-30 16:47:27 +08:00
2022-03-31 03:57:36 +08:00
def error_log(func):
2022-03-30 16:47:27 +08:00
"""
2022-03-31 03:57:36 +08:00
2022-03-30 16:47:27 +08:00
"""
@functools.wraps(func)
def internal(*args, **kwargs):
try:
func()
2022-03-31 03:57:36 +08:00
except Exception as e:
db = MongoHelper("tfse_v0.21")
info = {
"ip": request.remote_addr,
"request_info": {
"path": request.path,
"method": request.method,
"headers": request.headers.__str__(),
"args": request.args.__str__(),
"json": request.json.__str__()
},
"traceback": traceback.format_exc(),
"exception": type(e).__name__,
"is_solved": "no",
"time": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
}
db.insert_single_data(
"日志",
"异常日志",
info
)
return {"info": "发生什么事了?"}, 500
2022-03-30 16:47:27 +08:00
return func(*args, **kwargs)
return internal