Jingxun
8 months ago
1 changed files with 51 additions and 0 deletions
@ -0,0 +1,51 @@ |
|||
# encoding: utf-8 |
|||
""" |
|||
@author: Qiancj |
|||
@contact: qiancj@risenenergy.com |
|||
@file: exception_log |
|||
@create-time: 2023-09-26 09:55 |
|||
@description: The new python script |
|||
""" |
|||
|
|||
import traceback |
|||
from functools import wraps |
|||
|
|||
|
|||
class DecratorSet: |
|||
|
|||
@staticmethod |
|||
def log_dec(func): |
|||
@wraps(func) |
|||
def inner(*args, **kwargs): |
|||
status = False |
|||
out = {"code": 400500, "msg": "程序内部未知错误"} |
|||
try: |
|||
out = func(*args, **kwargs) |
|||
status = True |
|||
except Exception as e: |
|||
status = False |
|||
err = repr(e) |
|||
msg_content = traceback.format_exc() |
|||
# msg_content_list = msg_content.split("\n") |
|||
# pattern = re.compile(r'^\s*File\s*\S+[\\/]models\.py(\S*\s*)') |
|||
# msg_list = [i for i in msg_content_list if pattern.match(i)] |
|||
# location = msg_list[-1].strip() if msg_list else "未知错误" |
|||
out = {"status": 500500, "data": None, "msg": msg_content} |
|||
finally: |
|||
if not status: |
|||
func_name = func.__name__ |
|||
# redis.init_conn() |
|||
# redis.pub( |
|||
# "real_pub", |
|||
# str({ |
|||
# "func": func_name, |
|||
# "err": err, |
|||
# "params": msg_param, |
|||
# "location": location, |
|||
# "details": msg_content |
|||
# }) |
|||
# ) |
|||
# redis.close() |
|||
return out |
|||
|
|||
return inner |
Loading…
Reference in new issue