增加rjson非0的堆栈日志

This commit is contained in:
xaoyaoo 2024-08-03 20:04:53 +08:00
parent 83025996b0
commit c6f565bcdf
2 changed files with 12 additions and 3 deletions

View File

@ -156,7 +156,7 @@ def get_imgsrc(imgsrc):
f.write(out_bytes)
return send_file(imgsavepath)
else:
return ReJson(1001, body=original_img_path)
return ReJson(1001, body=f"{original_img_path} not exists")
elif imgsrc.startswith("http://") or imgsrc.startswith("https://"):
# 将?后面的参数连接到imgsrc
imgsrc = imgsrc + "?" + request.query_string.decode("utf-8") if request.query_string else imgsrc

View File

@ -1,4 +1,6 @@
import logging
import os
import traceback
loger_rjson = logging.getLogger("rjson")
@ -32,12 +34,19 @@ def ReJson(code: int, body: [dict, list] = None, msg: str = None, error: str = N
9999: {'code': 9999, 'body': body, 'msg': "未知错误!", "extra": extra},
}
rjson = situation.get(code, {'code': 9999, 'body': None, 'msg': "code错误", "extra": {}})
if code != 0:
loger_rjson.warning(f"\n{code=}\nbody=\n{rjson['body']}\nmsg={msg if msg else None}\n")
if body:
rjson['body'] = body
if msg:
rjson['msg'] = msg
if code != 0:
stack = traceback.extract_stack()
project_stack = [frame for frame in stack if "pywxdump" in frame.filename.lower() and
any(keyword in frame.filename for keyword in
["api", "db", "wx_core", "analyzer", "ui"])]
# 格式化调用栈信息
formatted_stack = ''.join(traceback.format_list(project_stack))
# stack_trace = ''.join(traceback.format_stack())
loger_rjson.warning(f"\n{code=}\nbody=\n{rjson['body']}\nmsg={rjson['msg']}\n{extra=}\n{formatted_stack}")
if error:
loger_rjson.error(error, exc_info=True)
return rjson