Refactor logging statements to use the new formatting syntax for improved readability and consistency across the codebase. This includes updating error, warning, and info logs in various modules such as system commands, configuration, core functionalities, and utilities. Additionally, minor adjustments were made to string formatting in backup and proxy features to enhance clarity.

This commit is contained in:
Tunglies
2025-06-27 23:30:35 +08:00
parent cf437e6d94
commit a574ced428
31 changed files with 153 additions and 162 deletions

View File

@@ -94,7 +94,7 @@ pub fn app_home_dir() -> Result<PathBuf> {
// 如果无法获取系统目录,则回退到可执行文件目录
let fallback_dir = PathBuf::from(exe_dir).join(".config").join(APP_ID);
log::warn!(target: "app", "Using fallback data directory: {:?}", fallback_dir);
log::warn!(target: "app", "Using fallback data directory: {fallback_dir:?}");
return Ok(fallback_dir);
}
};
@@ -102,7 +102,7 @@ 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);
log::error!(target: "app", "Failed to get the app home directory: {e}");
Err(anyhow::anyhow!("Failed to get the app homedirectory"))
}
}
@@ -127,7 +127,7 @@ 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);
log::error!(target: "app", "Failed to get the resource directory: {e}");
Err(anyhow::anyhow!("Failed to get the resource directory"))
}
}
@@ -203,7 +203,7 @@ pub fn service_log_file() -> Result<PathBuf> {
let log_dir = app_logs_dir()?.join("service");
let local_time = Local::now().format("%Y-%m-%d-%H%M").to_string();
let log_file = format!("{}.log", local_time);
let log_file = format!("{local_time}.log");
let log_file = log_dir.join(log_file);
let _ = std::fs::create_dir_all(&log_dir);

View File

@@ -38,7 +38,7 @@ static TRANSLATIONS: Lazy<HashMap<String, Value>> = Lazy::new(|| {
if let Some(locales_dir) = get_locales_dir() {
for lang in get_supported_languages() {
let file_path = locales_dir.join(format!("{}.json", lang));
let file_path = locales_dir.join(format!("{lang}.json"));
if let Ok(content) = fs::read_to_string(file_path) {
if let Ok(json) = serde_json::from_str(&content) {
translations.insert(lang.to_string(), json);

View File

@@ -31,7 +31,7 @@ fn init_log() -> Result<()> {
}
let local_time = Local::now().format("%Y-%m-%d-%H%M").to_string();
let log_file = format!("{}.log", local_time);
let log_file = format!("{local_time}.log");
let log_file = log_dir.join(log_file);
let log_pattern = match log_level {

View File

@@ -322,7 +322,7 @@ impl NetworkManager {
use crate::utils::resolve::VERSION;
let version = match VERSION.get() {
Some(v) => format!("clash-verge/v{}", v),
Some(v) => format!("clash-verge/v{v}"),
None => "clash-verge/unknown".to_string(),
};
@@ -401,7 +401,7 @@ impl NetworkManager {
let result = tokio::select! {
result = request.send() => result,
_ = cancel_rx => {
self.record_connection_error(&format!("Request interrupted for: {}", url));
self.record_connection_error(&format!("Request interrupted for: {url}"));
return Err(anyhow::anyhow!("Request interrupted after {} seconds", timeout_duration));
}
};

View File

@@ -121,7 +121,7 @@ pub async fn find_unused_port() -> Result<u16> {
.latest()
.verge_mixed_port
.unwrap_or(Config::clash().data().get_mixed_port());
log::warn!(target: "app", "use default port: {}", port);
log::warn!(target: "app", "use default port: {port}");
Ok(port)
}
}
@@ -530,7 +530,7 @@ pub fn create_window(is_show: bool) -> bool {
}
pub async fn resolve_scheme(param: String) -> Result<()> {
log::info!(target:"app", "received deep link: {}", param);
log::info!(target:"app", "received deep link: {param}");
let param_str = if param.starts_with("[") && param.len() > 4 {
param
@@ -568,7 +568,7 @@ pub async fn resolve_scheme(param: String) -> Result<()> {
match url_param {
Some(url) => {
log::info!(target:"app", "decoded subscription url: {}", url);
log::info!(target:"app", "decoded subscription url: {url}");
create_window(false);
match PrfItem::from_url(url.as_ref(), name, None, None).await {

View File

@@ -64,7 +64,7 @@ pub fn embed_server() {
.latest()
.verge_mixed_port
.unwrap_or(Config::clash().data().get_mixed_port());
let content = content.replace("%mixed-port%", &format!("{}", port));
let content = content.replace("%mixed-port%", &format!("{port}"));
warp::http::Response::builder()
.header("Content-Type", "application/x-ns-proxy-autoconfig")
.body(content)

View File

@@ -376,8 +376,7 @@ impl WindowManager {
let is_minimized = Self::is_main_window_minimized();
format!(
"窗口状态: {:?} | 可见: {} | 有焦点: {} | 最小化: {}",
state, is_visible, is_focused, is_minimized
"窗口状态: {state:?} | 可见: {is_visible} | 有焦点: {is_focused} | 最小化: {is_minimized}"
)
}
}