feat: 便携版EXE

This commit is contained in:
helloplhm-qwq
2023-11-11 18:16:03 +08:00
parent 6409caf638
commit 49cb760d4d
11 changed files with 96 additions and 29 deletions

View File

@ -11,6 +11,10 @@
import logging
import colorlog
import os
import traceback
from pygments import highlight
from pygments.lexers import PythonLexer
from pygments.formatters import TerminalFormatter
from .utils import sanitize_filename
from .variable import debug_mode, log_length_limit
@ -19,6 +23,13 @@ try:
except:
pass
def highlight_error(error):
# 对堆栈跟踪进行语法高亮
highlighted_traceback = highlight(error, PythonLexer(), TerminalFormatter())
# 返回语法高亮后的堆栈跟踪字符串
return str(highlighted_traceback)
class flaskLogHelper(logging.Handler):
# werkzeug日志转接器
def __init__(self, custom_logger):
@ -45,7 +56,7 @@ class log:
datefmt='%Y-%m-%d %H:%M:%S',
log_colors={
'DEBUG': 'cyan',
'INFO': 'green',
'INFO': 'white',
'WARNING': 'yellow',
'ERROR': 'red',
'CRITICAL': 'red,bg_white',
@ -120,7 +131,10 @@ class log:
self._logger.warning(message)
def error(self, message):
self._logger.error(message)
if (message.startswith('Traceback')):
self._logger.error('\n' + highlight_error(message))
else:
self._logger.error(message)
def critical(self, message):
self._logger.critical(message)