feat: 添加日志导出功能

This commit is contained in:
dmy
2026-03-03 14:26:58 +08:00
parent 02bfcc18e4
commit 3b590f9a1f
3 changed files with 97 additions and 1 deletions

View File

@@ -348,6 +348,53 @@ class EGMWebApp:
"message": f"保存失败: {str(e)}"
}
def export_log(self, log_text: str) -> Dict[str, Any]:
"""
导出日志为 TXT 文件,弹出保存对话框
Args:
log_text: 日志文本内容
Returns:
包含保存状态和路径的字典
"""
try:
# 生成默认文件名
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
default_filename = f'egm_log_{timestamp}.txt'
# 打开保存文件对话框
result = self.window.create_file_dialog(
webview.SAVE_DIALOG,
directory='',
save_filename=default_filename,
file_types=('Text Files (*.txt)', 'All files (*.*)')
)
if result and len(result) > 0:
file_path = result[0]
# 写入文件
with open(file_path, 'w', encoding='utf-8') as f:
f.write(log_text)
return {
"success": True,
"message": f"日志已保存到: {file_path}",
"file_path": file_path
}
else:
return {
"success": False,
"message": "用户取消了保存操作"
}
except Exception as e:
logger.error(f"导出日志失败: {str(e)}")
return {
"success": False,
"message": f"保存失败: {str(e)}"
}
def get_default_config(self) -> Dict[str, Any]:
"""
获取默认配置