Refactor logging to use a centralized logging utility across the application (#5277)

- Replaced direct log calls with a new logging macro that includes a logging type for better categorization.
- Updated logging in various modules including `merge.rs`, `mod.rs`, `tun.rs`, `clash.rs`, `profile.rs`, `proxy.rs`, `window.rs`, `lightweight.rs`, `guard.rs`, `autostart.rs`, `dirs.rs`, `dns.rs`, `scheme.rs`, `server.rs`, and `window_manager.rs`.
- Introduced logging types such as `Core`, `Network`, `ProxyMode`, `Window`, `Lightweight`, `Service`, and `File` to enhance log clarity and filtering.
This commit is contained in:
Tunglies
2025-11-01 20:47:01 +08:00
committed by GitHub
parent 50567d9b97
commit fb260fb33d
28 changed files with 473 additions and 210 deletions
+15 -5
View File
@@ -1,6 +1,8 @@
use crate::{
config::{Config, IVerge},
core::handle,
logging,
utils::logging::Type,
};
use std::env;
use tauri_plugin_clipboard_manager::ClipboardExt;
@@ -16,7 +18,11 @@ pub async fn toggle_system_proxy() {
&& auto_close_connection
&& let Err(err) = handle::Handle::mihomo().await.close_all_connections().await
{
log::error!(target: "app", "Failed to close all connections: {err}");
logging!(
error,
Type::ProxyMode,
"Failed to close all connections: {err}"
);
}
let patch_result = super::patch_verge(
@@ -30,7 +36,7 @@ pub async fn toggle_system_proxy() {
match patch_result {
Ok(_) => handle::Handle::refresh_verge(),
Err(err) => log::error!(target: "app", "{err}"),
Err(err) => logging!(error, Type::ProxyMode, "{err}"),
}
}
@@ -49,7 +55,7 @@ pub async fn toggle_tun_mode(not_save_file: Option<bool>) {
.await
{
Ok(_) => handle::Handle::refresh_verge(),
Err(err) => log::error!(target: "app", "{err}"),
Err(err) => logging!(error, Type::ProxyMode, "{err}"),
}
}
@@ -104,12 +110,16 @@ pub async fn copy_clash_env() {
}
"fish" => format!("set -x http_proxy {http_proxy}; set -x https_proxy {http_proxy}"),
_ => {
log::error!(target: "app", "copy_clash_env: Invalid env type! {env_type}");
logging!(
error,
Type::ProxyMode,
"copy_clash_env: Invalid env type! {env_type}"
);
return;
}
};
if cliboard.write_text(export_text).is_err() {
log::error!(target: "app", "Failed to write to clipboard");
logging!(error, Type::ProxyMode, "Failed to write to clipboard");
}
}