feat(desktop): Gateway URL 配置化 + Rust panic hook 崩溃报告
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
- api-urls.ts: GATEWAY_URLS 读 VITE_GATEWAY_HTTP/WS env - gateway-storage.ts: DEFAULT_GATEWAY_URL 读 VITE_GATEWAY_WS env - lib.rs: 添加 tracing_subscriber 初始化 + panic::set_hook 崩溃时自动写入 crash-reports/ 目录供诊断 - Cargo.toml: 添加 tracing-subscriber workspace 依赖
This commit is contained in:
@@ -49,6 +49,45 @@ mod dev_server;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
// Initialize tracing subscriber for structured logging
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
||||
)
|
||||
.with_thread_ids(true)
|
||||
.with_file(true)
|
||||
.with_line_number(true)
|
||||
.init();
|
||||
|
||||
// Install panic hook to capture crash info for diagnostics
|
||||
std::panic::set_hook(Box::new(|info| {
|
||||
let location = info.location().map(|l| format!("{}:{}", l.file(), l.line()))
|
||||
.unwrap_or_else(|| "unknown".into());
|
||||
let payload = if let Some(s) = info.payload().downcast_ref::<&str>() {
|
||||
s.to_string()
|
||||
} else if let Some(s) = info.payload().downcast_ref::<String>() {
|
||||
s.clone()
|
||||
} else {
|
||||
"unknown panic payload".into()
|
||||
};
|
||||
tracing::error!(location = %location, payload = %payload, "PANIC — application crashed");
|
||||
|
||||
// Write crash log to disk for post-mortem analysis
|
||||
if let Some(app_dir) = dirs::data_local_dir()
|
||||
.or_else(|| dirs::data_dir())
|
||||
{
|
||||
let crash_dir = app_dir.join("zclaw").join("crash-reports");
|
||||
let _ = std::fs::create_dir_all(&crash_dir);
|
||||
let timestamp = chrono::Local::now().format("%Y%m%d_%H%M%S");
|
||||
let crash_file = crash_dir.join(format!("crash_{}.log", timestamp));
|
||||
let _ = std::fs::write(&crash_file, format!(
|
||||
"ZCLAW Crash Report\n==================\nTime: {}\nLocation: {}\nPayload: {}\n\n{:?}",
|
||||
chrono::Local::now().to_rfc3339(), location, payload, info,
|
||||
));
|
||||
}
|
||||
}));
|
||||
|
||||
// Start development server when dev-server feature is enabled
|
||||
#[cfg(feature = "dev-server")]
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user