fix: 修复某些时候因错误无法格式化导致程序崩溃的问题

This commit is contained in:
helloplhm-qwq 2024-03-03 14:03:30 +08:00
parent 7ea698e147
commit fa53fdb4e1
No known key found for this signature in database
GPG Key ID: 6BE1B64B905567C7

View File

@ -84,6 +84,7 @@ def stack_info(stack_trace_line):
sys.stderr.write(f"日志模块出错,本次日志可能无法记录,请报告给开发者: \n" + traceback.format_exc()) sys.stderr.write(f"日志模块出错,本次日志可能无法记录,请报告给开发者: \n" + traceback.format_exc())
def highlight_error(e): def highlight_error(e):
try:
if (isinstance(e, Exception)): if (isinstance(e, Exception)):
error = stack_error(e) error = stack_error(e)
else: else:
@ -136,6 +137,12 @@ def highlight_error(e):
# traceback.print_exc() # traceback.print_exc()
final.append(i) final.append(i)
return "\n".join(final).replace('\n\n', '\n') return "\n".join(final).replace('\n\n', '\n')
except:
logger.error('格式化错误失败,使用默认格式\n' + traceback.format_exc())
if (isinstance(e, Exception)):
return stack_error(e)
else:
return e
class LogHelper(logging.Handler): class LogHelper(logging.Handler):
# 日志转接器 # 日志转接器