From ee3ffaef1db582606a9c22e01a4214ba4477be81 Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Wed, 13 Aug 2025 16:24:57 +0800 Subject: [PATCH] refactor: simplify log warning message formatting and remove unused LogLevel enum --- src-tauri/src/feat/window.rs | 2 +- src-tauri/src/ipc/logs.rs | 47 ------------------------------------ 2 files changed, 1 insertion(+), 48 deletions(-) diff --git a/src-tauri/src/feat/window.rs b/src-tauri/src/feat/window.rs index a21dd8ce..951c2bf7 100644 --- a/src-tauri/src/feat/window.rs +++ b/src-tauri/src/feat/window.rs @@ -112,7 +112,7 @@ async fn clean_async() -> bool { true } Ok(Err(e)) => { - log::warn!(target: "app", "禁用TUN模式失败: {}", e); + log::warn!(target: "app", "禁用TUN模式失败: {e}"); false } Err(_) => { diff --git a/src-tauri/src/ipc/logs.rs b/src-tauri/src/ipc/logs.rs index 78858bd3..83248327 100644 --- a/src-tauri/src/ipc/logs.rs +++ b/src-tauri/src/ipc/logs.rs @@ -1,5 +1,4 @@ use serde::{Deserialize, Serialize}; -use std::fmt; use std::{collections::VecDeque, sync::Arc, time::Instant}; use tokio::{sync::RwLock, task::JoinHandle, time::Duration}; @@ -23,52 +22,6 @@ pub struct LogItem { pub time: String, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -enum LogLevel { - All = 0, // 显示所有级别(仅用于过滤) - Debug = 1, // Debug 日志类型 / Debug 过滤级别(显示 debug、warning、error,排除info) - Info = 2, // Info 日志类型 / Info 过滤级别(显示 info、warning、error) - Warning = 3, // Warning 日志类型 / Warning 过滤级别(显示 warning、error) - Error = 4, // Error 日志类型 / Error 过滤级别(只显示 error) -} - -impl fmt::Display for LogLevel { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - LogLevel::Debug => write!(f, "debug"), - LogLevel::Info => write!(f, "info"), - LogLevel::Warning => write!(f, "warning"), - LogLevel::Error => write!(f, "error"), - LogLevel::All => write!(f, "all"), - } - } -} - -impl TryFrom<&str> for LogLevel { - type Error = String; - - fn try_from(value: &str) -> Result>::Error> { - match value.to_lowercase().as_str() { - "debug" => Ok(LogLevel::Debug), - "info" => Ok(LogLevel::Info), - "warning" | "warn" => Ok(LogLevel::Warning), - "error" | "err" => Ok(LogLevel::Error), - "all" => Ok(LogLevel::All), - _ => Err(format!("Invalid log level: '{value}'")), - } - } -} - -impl TryFrom for LogLevel { - type Error = String; - - fn try_from(value: String) -> Result>::Error> { - LogLevel::try_from(value.as_str()) - } -} - -impl LogLevel {} - impl LogItem { fn new(log_type: String, payload: String) -> Self { use std::time::{SystemTime, UNIX_EPOCH};