52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
|
import time
|
||
|
|
||
|
from flask import request
|
||
|
import functools
|
||
|
import traceback
|
||
|
|
||
|
from DBHelper.MongoHelper import MongoHelper
|
||
|
from Utils.ErrorUtil import ObjColumnCheckError
|
||
|
|
||
|
|
||
|
def error_log(func):
|
||
|
"""
|
||
|
异常日志
|
||
|
"""
|
||
|
def save_error_log(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
|
||
|
)
|
||
|
|
||
|
@functools.wraps(func)
|
||
|
def internal(*args, **kwargs):
|
||
|
try:
|
||
|
func()
|
||
|
except ObjColumnCheckError as e:
|
||
|
save_error_log(e)
|
||
|
return {"info": e.__str__()}, 400
|
||
|
except Exception as e:
|
||
|
save_error_log(e)
|
||
|
return {"info": "发生什么事了?"}, 400
|
||
|
|
||
|
return func(*args, **kwargs)
|
||
|
return internal
|