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

View File

@@ -62,7 +62,11 @@ pub fn app_home_dir() -> Result<PathBuf> {
match app_handle.path().data_dir() {
Ok(dir) => Ok(dir.join(APP_ID)),
Err(e) => {
log::error!(target: "app", "Failed to get the app home directory: {e}");
logging!(
error,
Type::File,
"Failed to get the app home directory: {e}"
);
Err(anyhow::anyhow!("Failed to get the app homedirectory"))
}
}
@@ -76,7 +80,11 @@ pub fn app_resources_dir() -> Result<PathBuf> {
match app_handle.path().resource_dir() {
Ok(dir) => Ok(dir.join("resources")),
Err(e) => {
log::error!(target: "app", "Failed to get the resource directory: {e}");
logging!(
error,
Type::File,
"Failed to get the resource directory: {e}"
);
Err(anyhow::anyhow!("Failed to get the resource directory"))
}
}
@@ -229,7 +237,11 @@ pub fn ensure_mihomo_safe_dir() -> Option<PathBuf> {
if home_config.exists() || fs::create_dir_all(&home_config).is_ok() {
Some(home_config)
} else {
log::error!(target: "app", "Failed to create safe directory: {home_config:?}");
logging!(
error,
Type::File,
"Failed to create safe directory: {home_config:?}"
);
None
}
})