refactor(gui): format_gui_log_line 内置到 log_pipeline,主文件保留兼容 re-export (178 → 169)

This commit is contained in:
Your Name committed 2026-05-30 20:08:35 +08:00
1 parent 0d4796744d
commit 95459607dc
2 files changed
+20 -19

No files matched your search

+15 -5
View File
@@ -15,10 +15,20 @@ from gui.components.log_writer import ThreadSafeLogWriter
_LOGGER = logging.getLogger("gui.gui_app")
def setup_log_pipeline(
*,
format_gui_log_line: Callable[[str], str],
) -> Tuple["queue.Queue[str]", Any, Callable[[str], None], Any]:
def _format_gui_log_line(line: str) -> str:
"""将完整日志行转换为 GUI 显示用的精简版本。
实际实现位于 ``gui.components.log_viewer``,失败时回退到原始字符串。
"""
try:
from gui.components.log_viewer import format_gui_log_line as _impl
return _impl(line)
except Exception:
return (line or "").rstrip("\n")
def setup_log_pipeline() -> Tuple["queue.Queue[str]", Any, Callable[[str], None], Any]:
"""构建 log queue + ThreadSafeLogWriter + on_line + Runner。
返回 ``(q, log_writer, on_line, runner)``,主程序后续把 ``runner`` 传入按钮回调,
@@ -31,7 +41,7 @@ def setup_log_pipeline(
"""处理日志行:GUI 显示用精简版本,文件写入用完整版本"""
# GUI 显示:使用精简后的版本
try:
display_line = format_gui_log_line(line)
display_line = _format_gui_log_line(line)
except Exception:
display_line = line
q.put(display_line)