feat: Add logging and error handling enhancements
- Introduced new logging modules for action tracking, error logging, and performance tracking to improve observability. - Added functions for retrieving debug and error log paths in `path_config.py`. - Updated various components to utilize the new logging system, enhancing error handling and performance diagnostics. - Implemented a GUI component for viewing error logs, improving user experience in monitoring application issues. - Cleaned up unnecessary blank lines and improved code readability across multiple files.
This commit is contained in:
1 parent
bdf9312bc9
commit
efe6e2252f
48 files changed
+2165
-320
No files matched your search
+55
-18
@@ -808,16 +808,30 @@ class Runner:
|
||||
else:
|
||||
self._on_line("[警告] 未找到 adb.exe:请安装 platform-tools 或将 adb 加入 PATH")
|
||||
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
env=env,
|
||||
cwd=path_config.PROJECT_ROOT,
|
||||
)
|
||||
try:
|
||||
p = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
env=env,
|
||||
cwd=path_config.PROJECT_ROOT,
|
||||
)
|
||||
except FileNotFoundError as e:
|
||||
raise RuntimeError(
|
||||
f"无法启动进程:找不到 Python 解释器或 run_cli.py 文件\n"
|
||||
f"Python路径: {sys.executable}\n"
|
||||
f"run_cli.py路径: {run_cli_path}\n"
|
||||
f"原始错误: {e}"
|
||||
)
|
||||
except Exception as e:
|
||||
raise RuntimeError(
|
||||
f"启动进程失败:{e}\n"
|
||||
f"命令: {' '.join(cmd)}\n"
|
||||
f"工作目录: {path_config.PROJECT_ROOT}"
|
||||
)
|
||||
|
||||
with self._lock:
|
||||
self._proc = p
|
||||
@@ -842,17 +856,40 @@ class Runner:
|
||||
out = self._proc.stdout
|
||||
if out is None:
|
||||
return
|
||||
for line in out:
|
||||
cleaned_line = line.rstrip("\n")
|
||||
self._on_line(cleaned_line)
|
||||
try:
|
||||
# 读取所有输出
|
||||
has_output = False
|
||||
for line in out:
|
||||
has_output = True
|
||||
cleaned_line = line.rstrip("\n")
|
||||
self._on_line(cleaned_line)
|
||||
try:
|
||||
self._update_stats_from_line(cleaned_line)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 等待进程结束
|
||||
rc = self._proc.wait()
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
|
||||
# 如果进程立即退出且没有输出,说明可能有问题
|
||||
if not has_output and rc != 0:
|
||||
self._on_line(f"[警告] 进程立即退出,退出码={rc},没有输出")
|
||||
self._on_line("[提示] 可能的原因:run_cli.py启动失败、导入错误或配置错误")
|
||||
else:
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
except Exception as e:
|
||||
# 读取输出时出错
|
||||
try:
|
||||
self._update_stats_from_line(cleaned_line)
|
||||
self._on_line(f"[错误] 读取进程输出失败: {e}")
|
||||
rc = self._proc.poll()
|
||||
if rc is not None:
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
except Exception:
|
||||
pass
|
||||
rc = self._proc.wait()
|
||||
with self._lock:
|
||||
self._exit_code = rc
|
||||
self._on_line(f"[进程结束] exit_code={rc}")
|
||||
|
||||
self._reader_thread = threading.Thread(target=_reader, daemon=True)
|
||||
self._reader_thread.start()
|
||||
|
||||
Reference in new issue
Block a user