feat(logging): introduce clash-verge-logging crate for management (#5486)

* feat(logging): introduce clash-verge-logging crate for management

- Added a new crate `clash-verge-logging` with dependencies on `log`, `tokio`, `compact_str`, and `flexi_logger`.
- Implemented logging types and macros for structured logging across the application.
- Replaced existing logging imports with the new `clash_verge_logging` crate in various modules.
- Updated logging functionality to support different logging types and error handling.
- Refactored code to improve logging consistency and maintainability.

* fix(logging): update import paths for clash_verge_logging in linux.rs and dns.rs

* fix(logging): update import statement for clash_verge_logging in windows.rs
This commit is contained in:
Tunglies
2025-11-17 10:42:57 +08:00
committed by GitHub
parent 635f63e9e5
commit 0866b93175
61 changed files with 145 additions and 169 deletions

11
src-tauri/Cargo.lock generated
View File

@@ -1115,6 +1115,7 @@ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"boa_engine", "boa_engine",
"chrono", "chrono",
"clash-verge-logging",
"clash_verge_logger", "clash_verge_logger",
"clash_verge_service_ipc", "clash_verge_service_ipc",
"compact_str", "compact_str",
@@ -1176,6 +1177,16 @@ dependencies = [
"zip 6.0.0", "zip 6.0.0",
] ]
[[package]]
name = "clash-verge-logging"
version = "0.1.0"
dependencies = [
"compact_str",
"flexi_logger",
"log",
"tokio",
]
[[package]] [[package]]
name = "clash_verge_logger" name = "clash_verge_logger"
version = "0.2.0" version = "0.2.0"

View File

@@ -10,6 +10,19 @@ edition = "2024"
build = "build.rs" build = "build.rs"
rust-version = "1.91" rust-version = "1.91"
[workspace]
members = ["crates/*"]
resolver = "2"
[features]
default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
verge-dev = ["clash_verge_logger/color"]
tauri-dev = ["clash-verge-logging/tauri-dev"]
tokio-trace = ["console-subscriber"]
clippy = ["tauri/test"]
tracing = []
[package.metadata.bundle] [package.metadata.bundle]
identifier = "io.github.clash-verge-rev.clash-verge-rev" identifier = "io.github.clash-verge-rev.clash-verge-rev"
@@ -17,13 +30,16 @@ identifier = "io.github.clash-verge-rev.clash-verge-rev"
tauri-build = { version = "2.5.2", features = [] } tauri-build = { version = "2.5.2", features = [] }
[dependencies] [dependencies]
clash-verge-logging = { path = "crates/clash-verge-logging" }
parking_lot = { workspace = true } parking_lot = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }
tokio = { workspace = true } tokio = { workspace = true }
draft = { workspace = true } draft = { workspace = true }
compact_str = { workspace = true }
flexi_logger = { workspace = true }
log = { workspace = true }
warp = { version = "0.4.2", features = ["server"] } warp = { version = "0.4.2", features = ["server"] }
open = "5.3.2" open = "5.3.2"
log = "0.4.28"
dunce = "1.0.5" dunce = "1.0.5"
nanoid = "0.4" nanoid = "0.4"
chrono = "0.4.42" chrono = "0.4.42"
@@ -69,9 +85,7 @@ scopeguard = "1.2.0"
tauri-plugin-notification = "2.3.3" tauri-plugin-notification = "2.3.3"
tokio-stream = "0.1.17" tokio-stream = "0.1.17"
backoff = { version = "0.4.0", features = ["tokio"] } backoff = { version = "0.4.0", features = ["tokio"] }
compact_str = { version = "0.9.0", features = ["serde"] }
tauri-plugin-http = "2.5.4" tauri-plugin-http = "2.5.4"
flexi_logger = "0.31.7"
console-subscriber = { version = "0.5.0", optional = true } console-subscriber = { version = "0.5.0", optional = true }
tauri-plugin-devtools = { version = "2.0.1" } tauri-plugin-devtools = { version = "2.0.1" }
tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" } tauri-plugin-mihomo = { git = "https://github.com/clash-verge-rev/tauri-plugin-mihomo" }
@@ -133,19 +147,9 @@ tokio = { version = "1.48.0", features = [
"time", "time",
"sync", "sync",
] } ] }
compact_str = { version = "0.9.0", features = ["serde"] }
[workspace] flexi_logger = "0.31.7"
members = ["crates/*"] log = "0.4.28"
resolver = "2"
[features]
default = ["custom-protocol"]
custom-protocol = ["tauri/custom-protocol"]
verge-dev = ["clash_verge_logger/color"]
tauri-dev = []
tokio-trace = ["console-subscriber"]
clippy = ["tauri/test"]
tracing = []
[profile.release] [profile.release]
panic = "abort" panic = "abort"

View File

@@ -0,0 +1,14 @@
[package]
name = "clash-verge-logging"
version = "0.1.0"
edition = "2024"
[dependencies]
log = { workspace = true }
tokio = { workspace = true }
compact_str = { workspace = true }
flexi_logger = { workspace = true }
[features]
default = []
tauri-dev = []

View File

@@ -34,6 +34,7 @@ pub enum Type {
} }
impl fmt::Display for Type { impl fmt::Display for Type {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Self::Cmd => write!(f, "[Cmd]"), Self::Cmd => write!(f, "[Cmd]"),
@@ -58,29 +59,6 @@ impl fmt::Display for Type {
} }
} }
#[macro_export]
macro_rules! error {
($result: expr) => {
log::error!(target: "app", "{}", $result);
};
}
/// wrap the anyhow error
/// transform the error to String
#[macro_export]
macro_rules! wrap_err {
// Case 1: Future<Result<T, E>>
($stat:expr, async) => {{
match $stat.await {
Ok(a) => Ok::<_, ::anyhow::Error>(a),
Err(err) => {
log::error!(target: "app", "{}", err);
Err(::anyhow::Error::msg(err.to_string()))
}
}
}};
}
#[macro_export] #[macro_export]
macro_rules! logging { macro_rules! logging {
// 不带 print 参数的版本(默认不打印) // 不带 print 参数的版本(默认不打印)
@@ -104,6 +82,7 @@ macro_rules! logging_error {
}; };
} }
#[inline]
pub fn write_sidecar_log( pub fn write_sidecar_log(
writer: MutexGuard<'_, FileLogWriter>, writer: MutexGuard<'_, FileLogWriter>,
now: &mut DeferredNow, now: &mut DeferredNow,
@@ -143,6 +122,7 @@ impl<'a> NoModuleFilter<'a> {
#[cfg(not(feature = "tauri-dev"))] #[cfg(not(feature = "tauri-dev"))]
impl<'a> LogLineFilter for NoModuleFilter<'a> { impl<'a> LogLineFilter for NoModuleFilter<'a> {
#[inline]
fn write( fn write(
&self, &self,
now: &mut DeferredNow, now: &mut DeferredNow,

View File

@@ -3,12 +3,10 @@ use crate::core::sysopt::Sysopt;
use crate::utils::resolve::ui::{self, UiReadyStage}; use crate::utils::resolve::ui::{self, UiReadyStage};
use crate::{ use crate::{
cmd::StringifyErr as _, cmd::StringifyErr as _,
feat, logging, feat,
utils::{ utils::dirs::{self, PathBufExec as _},
dirs::{self, PathBufExec as _},
logging::Type,
},
}; };
use clash_verge_logging::{Type, logging};
use smartstring::alias::String; use smartstring::alias::String;
use std::path::Path; use std::path::Path;
use tauri::{AppHandle, Manager as _}; use tauri::{AppHandle, Manager as _};

View File

@@ -1,4 +1,5 @@
use super::CmdResult; use super::CmdResult;
use crate::feat;
use crate::utils::dirs; use crate::utils::dirs;
use crate::{ use crate::{
cmd::StringifyErr as _, cmd::StringifyErr as _,
@@ -6,7 +7,7 @@ use crate::{
constants, constants,
core::{CoreManager, handle, validate::CoreConfigValidator}, core::{CoreManager, handle, validate::CoreConfigValidator},
}; };
use crate::{feat, logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use compact_str::CompactString; use compact_str::CompactString;
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,10 +1,9 @@
use std::sync::Arc; use std::sync::Arc;
use clash_verge_logging::{Type, logging};
use regex::Regex; use regex::Regex;
use reqwest::{Client, cookie::Jar}; use reqwest::{Client, cookie::Jar};
use crate::{logging, utils::logging::Type};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -1,7 +1,7 @@
use regex::Regex; use regex::Regex;
use reqwest::Client; use reqwest::Client;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -1,7 +1,7 @@
use regex::Regex; use regex::Regex;
use reqwest::Client; use reqwest::Client;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -4,7 +4,7 @@ use reqwest::Client;
use tauri::command; use tauri::command;
use tokio::{sync::Mutex, task::JoinSet}; use tokio::{sync::Mutex, task::JoinSet};
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
mod bahamut; mod bahamut;
mod bilibili; mod bilibili;

View File

@@ -1,7 +1,7 @@
use reqwest::Client; use reqwest::Client;
use serde_json::Value; use serde_json::Value;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -1,7 +1,7 @@
use regex::Regex; use regex::Regex;
use reqwest::Client; use reqwest::Client;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -1,7 +1,7 @@
use regex::Regex; use regex::Regex;
use reqwest::Client; use reqwest::Client;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::UnlockItem; use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string}; use super::utils::{country_code_to_emoji, get_local_date_string};

View File

@@ -1,6 +1,6 @@
use super::CmdResult; use super::CmdResult;
use crate::cmd::StringifyErr as _; use crate::cmd::StringifyErr as _;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use gethostname::gethostname; use gethostname::gethostname;
use network_interface::NetworkInterface; use network_interface::NetworkInterface;
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;

View File

@@ -10,12 +10,13 @@ use crate::{
profiles_append_item_safe, profiles_append_item_safe,
}, },
core::{CoreManager, handle, timer::Timer, tray::Tray}, core::{CoreManager, handle, timer::Timer, tray::Tray},
feat, logging, feat,
module::auto_backup::{AutoBackupManager, AutoBackupTrigger}, module::auto_backup::{AutoBackupManager, AutoBackupTrigger},
process::AsyncHandler, process::AsyncHandler,
ret_err, ret_err,
utils::{dirs, help, logging::Type}, utils::{dirs, help},
}; };
use clash_verge_logging::{Type, logging};
use scopeguard::defer; use scopeguard::defer;
use smartstring::alias::String; use smartstring::alias::String;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};

View File

@@ -1,5 +1,5 @@
use super::CmdResult; use super::CmdResult;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
// TODO: 前端通过 emit 发送更新事件, tray 监听更新事件 // TODO: 前端通过 emit 发送更新事件, tray 监听更新事件
/// 同步托盘和GUI的代理选择状态 /// 同步托盘和GUI的代理选择状态

View File

@@ -1,8 +1,7 @@
use super::CmdResult; use super::CmdResult;
use crate::{ use crate::{cmd::StringifyErr as _, config::Config, core::CoreManager};
cmd::StringifyErr as _, config::Config, core::CoreManager, logging_error, utils::logging::Type,
};
use anyhow::{Context as _, anyhow}; use anyhow::{Context as _, anyhow};
use clash_verge_logging::{Type, logging_error};
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;
use smartstring::alias::String; use smartstring::alias::String;
use std::collections::HashMap; use std::collections::HashMap;

View File

@@ -3,10 +3,10 @@ use crate::{
cmd::StringifyErr as _, cmd::StringifyErr as _,
config::{Config, PrfItem}, config::{Config, PrfItem},
core::{CoreManager, handle, validate::CoreConfigValidator}, core::{CoreManager, handle, validate::CoreConfigValidator},
logging,
module::auto_backup::{AutoBackupManager, AutoBackupTrigger}, module::auto_backup::{AutoBackupManager, AutoBackupTrigger},
utils::{dirs, logging::Type}, utils::dirs,
}; };
use clash_verge_logging::{Type, logging};
use smartstring::alias::String; use smartstring::alias::String;
use tokio::fs; use tokio::fs;

View File

@@ -3,10 +3,9 @@ use std::sync::Arc;
use super::CmdResult; use super::CmdResult;
use crate::{ use crate::{
core::{CoreManager, handle, manager::RunningMode}, core::{CoreManager, handle, manager::RunningMode},
logging,
module::sysinfo::PlatformSpecification, module::sysinfo::PlatformSpecification,
utils::logging::Type,
}; };
use clash_verge_logging::{Type, logging};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use deelevate::{PrivilegeLevel, Token}; use deelevate::{PrivilegeLevel, Token};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;

View File

@@ -1,9 +1,6 @@
use super::CmdResult; use super::CmdResult;
use crate::{ use crate::core::{handle, validate::CoreConfigValidator};
core::{handle, validate::CoreConfigValidator}, use clash_verge_logging::{Type, logging};
logging,
utils::logging::Type,
};
use smartstring::alias::String; use smartstring::alias::String;
/// 发送脚本验证通知消息 /// 发送脚本验证通知消息

View File

@@ -2,8 +2,8 @@ use crate::config::Config;
use crate::constants::{network, tun as tun_const}; use crate::constants::{network, tun as tun_const};
use crate::utils::dirs::{ipc_path, path_to_str}; use crate::utils::dirs::{ipc_path, path_to_str};
use crate::utils::{dirs, help}; use crate::utils::{dirs, help};
use crate::{logging, utils::logging::Type};
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_yaml_ng::{Mapping, Value}; use serde_yaml_ng::{Mapping, Value};
use std::{ use std::{

View File

@@ -4,11 +4,12 @@ use crate::{
config::{PrfItem, profiles_append_item_safe}, config::{PrfItem, profiles_append_item_safe},
constants::{files, timing}, constants::{files, timing},
core::{CoreManager, handle, service, tray, validate::CoreConfigValidator}, core::{CoreManager, handle, service, tray, validate::CoreConfigValidator},
enhance, logging, logging_error, enhance,
utils::{dirs, help, logging::Type}, utils::{dirs, help},
}; };
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use backoff::{Error as BackoffError, ExponentialBackoff}; use backoff::{Error as BackoffError, ExponentialBackoff};
use clash_verge_logging::{Type, logging, logging_error};
use draft::Draft; use draft::Draft;
use smartstring::alias::String; use smartstring::alias::String;
use std::path::PathBuf; use std::path::PathBuf;

View File

@@ -3,8 +3,8 @@ use crate::utils::{
dirs::{self, PathBufExec as _}, dirs::{self, PathBufExec as _},
help, help,
}; };
use crate::{logging, utils::logging::Type};
use anyhow::{Context as _, Result, bail}; use anyhow::{Context as _, Result, bail};
use clash_verge_logging::{Type, logging};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,10 +1,10 @@
use crate::config::Config; use crate::config::Config;
use crate::{ use crate::{
config::{DEFAULT_PAC, deserialize_encrypted, serialize_encrypted}, config::{DEFAULT_PAC, deserialize_encrypted, serialize_encrypted},
logging, utils::{dirs, help, i18n},
utils::{dirs, help, i18n, logging::Type},
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging};
use log::LevelFilter; use log::LevelFilter;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,12 +1,8 @@
use crate::constants::files::DNS_CONFIG; use crate::constants::files::DNS_CONFIG;
use crate::{ use crate::{config::Config, process::AsyncHandler, utils::dirs};
config::Config,
logging,
process::AsyncHandler,
utils::{dirs, logging::Type},
};
use anyhow::Error; use anyhow::Error;
use arc_swap::{ArcSwap, ArcSwapOption}; use arc_swap::{ArcSwap, ArcSwapOption};
use clash_verge_logging::{Type, logging};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use reqwest_dav::list_cmd::{ListEntity, ListFile}; use reqwest_dav::list_cmd::{ListEntity, ListFile};
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,11 +1,12 @@
use crate::process::AsyncHandler; use crate::process::AsyncHandler;
use crate::utils::notification::{NotificationEvent, notify_event}; use crate::utils::notification::{NotificationEvent, notify_event};
use crate::{ use crate::{
config::Config, core::handle, feat, logging, module::lightweight::entry_lightweight_mode, config::Config, core::handle, feat, module::lightweight::entry_lightweight_mode,
singleton_with_logging, utils::logging::Type, singleton_with_logging,
}; };
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use arc_swap::ArcSwap; use arc_swap::ArcSwap;
use clash_verge_logging::{Type, logging};
use smartstring::alias::String; use smartstring::alias::String;
use std::{collections::HashMap, fmt, str::FromStr, sync::Arc}; use std::{collections::HashMap, fmt, str::FromStr, sync::Arc};
use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt as _, ShortcutState}; use tauri_plugin_global_shortcut::{Code, GlobalShortcutExt as _, ShortcutState};

View File

@@ -3,10 +3,10 @@ use crate::{
config::{Config, ConfigType, IRuntime}, config::{Config, ConfigType, IRuntime},
constants::timing, constants::timing,
core::{handle, validate::CoreConfigValidator}, core::{handle, validate::CoreConfigValidator},
logging, utils::{dirs, help},
utils::{dirs, help, logging::Type},
}; };
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use clash_verge_logging::{Type, logging};
use smartstring::alias::String; use smartstring::alias::String;
use std::{path::PathBuf, time::Instant}; use std::{path::PathBuf, time::Instant};
use tauri_plugin_mihomo::Error as MihomoError; use tauri_plugin_mihomo::Error as MihomoError;

View File

@@ -1,15 +1,12 @@
use super::{CoreManager, RunningMode}; use super::{CoreManager, RunningMode};
use crate::cmd::StringifyErr as _; use crate::cmd::StringifyErr as _;
use crate::config::{Config, IVerge}; use crate::config::{Config, IVerge};
use crate::{ use crate::core::{
core::{ logger::CLASH_LOGGER,
logger::CLASH_LOGGER, service::{SERVICE_MANAGER, ServiceStatus},
service::{SERVICE_MANAGER, ServiceStatus},
},
logging,
utils::logging::Type,
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging};
use smartstring::alias::String; use smartstring::alias::String;
impl CoreManager { impl CoreManager {

View File

@@ -5,13 +5,10 @@ use crate::{
core::{handle, logger::CLASH_LOGGER, service}, core::{handle, logger::CLASH_LOGGER, service},
logging, logging,
process::CommandChildGuard, process::CommandChildGuard,
utils::{ utils::{dirs, init::sidecar_writer},
dirs,
init::sidecar_writer,
logging::{SharedWriter, Type, write_sidecar_log},
},
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{SharedWriter, Type, write_sidecar_log};
use compact_str::CompactString; use compact_str::CompactString;
use flexi_logger::DeferredNow; use flexi_logger::DeferredNow;
use log::Level; use log::Level;

View File

@@ -1,9 +1,6 @@
use super::handle::Handle; use super::handle::Handle;
use crate::{ use crate::constants::{retry, timing};
constants::{retry, timing}, use clash_verge_logging::{Type, logging};
logging,
utils::logging::Type,
};
use parking_lot::RwLock; use parking_lot::RwLock;
use smartstring::alias::String; use smartstring::alias::String;
use std::{ use std::{

View File

@@ -1,10 +1,10 @@
use crate::{ use crate::{
config::Config, config::Config,
core::tray, core::tray,
logging, logging_error, utils::{dirs, init::service_writer_config},
utils::{dirs, init::service_writer_config, logging::Type},
}; };
use anyhow::{Context as _, Result, bail}; use anyhow::{Context as _, Result, bail};
use clash_verge_logging::{Type, logging, logging_error};
use clash_verge_service_ipc::CoreConfig; use clash_verge_service_ipc::CoreConfig;
use compact_str::CompactString; use compact_str::CompactString;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;

View File

@@ -3,10 +3,10 @@ use crate::utils::autostart as startup_shortcut;
use crate::{ use crate::{
config::{Config, IVerge}, config::{Config, IVerge},
core::handle::Handle, core::handle::Handle,
logging, logging_error, singleton_lazy, singleton_lazy,
utils::logging::Type,
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging, logging_error};
use parking_lot::RwLock; use parking_lot::RwLock;
use scopeguard::defer; use scopeguard::defer;
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,10 +1,10 @@
use crate::{ use crate::{
config::Config, config::Config,
core::{CoreManager, manager::RunningMode, sysopt::Sysopt}, core::{CoreManager, manager::RunningMode, sysopt::Sysopt},
feat, logging, logging_error, singleton, feat, singleton,
utils::logging::Type,
}; };
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};
use clash_verge_logging::{Type, logging, logging_error};
use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder}; use delay_timer::prelude::{DelayTimer, DelayTimerBuilder, TaskBuilder};
use parking_lot::RwLock; use parking_lot::RwLock;
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -9,7 +9,7 @@ use crate::config::{Config, ConfigType};
use crate::core::handle; use crate::core::handle;
use crate::singleton_lazy; use crate::singleton_lazy;
use crate::utils::dirs; use crate::utils::dirs;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
pub struct CoreConfigValidator { pub struct CoreConfigValidator {
is_processing: AtomicBool, is_processing: AtomicBool,

View File

@@ -1,4 +1,4 @@
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use super::use_lowercase; use super::use_lowercase;
use serde_yaml_ng::{self, Mapping, Value}; use serde_yaml_ng::{self, Mapping, Value};

View File

@@ -16,7 +16,7 @@ use self::{
use crate::constants; use crate::constants;
use crate::utils::dirs; use crate::utils::dirs;
use crate::{config::Config, utils::tmpl}; use crate::{config::Config, utils::tmpl};
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;
use smartstring::alias::String; use smartstring::alias::String;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};

View File

@@ -1,16 +1,15 @@
use crate::{ use crate::{
config::{Config, IVerge}, config::{Config, IVerge},
core::backup, core::backup,
logging,
process::AsyncHandler, process::AsyncHandler,
utils::{ utils::{
dirs::{PathBufExec as _, app_home_dir, local_backup_dir, verge_path}, dirs::{PathBufExec as _, app_home_dir, local_backup_dir, verge_path},
help, help,
logging::Type,
}, },
}; };
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
use chrono::Utc; use chrono::Utc;
use clash_verge_logging::{Type, logging};
use reqwest_dav::list_cmd::ListFile; use reqwest_dav::list_cmd::ListFile;
use serde::Serialize; use serde::Serialize;
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,10 +1,10 @@
use crate::{ use crate::{
config::Config, config::Config,
core::{CoreManager, handle, tray}, core::{CoreManager, handle, tray},
logging, logging_error,
process::AsyncHandler, process::AsyncHandler,
utils::{self, logging::Type, resolve}, utils::{self, resolve},
}; };
use clash_verge_logging::{Type, logging, logging_error};
use serde_yaml_ng::{Mapping, Value}; use serde_yaml_ng::{Mapping, Value};
use smartstring::alias::String; use smartstring::alias::String;

View File

@@ -1,11 +1,10 @@
use crate::{ use crate::{
config::{Config, IVerge}, config::{Config, IVerge},
core::{CoreManager, handle, hotkey, sysopt, tray}, core::{CoreManager, handle, hotkey, sysopt, tray},
logging, logging_error,
module::{auto_backup::AutoBackupManager, lightweight}, module::{auto_backup::AutoBackupManager, lightweight},
utils::logging::Type,
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging, logging_error};
use draft::SharedBox; use draft::SharedBox;
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;

View File

@@ -2,10 +2,9 @@ use crate::{
cmd, cmd,
config::{Config, PrfItem, PrfOption, profiles::profiles_draft_update_item_safe}, config::{Config, PrfItem, PrfOption, profiles::profiles_draft_update_item_safe},
core::{CoreManager, handle, tray}, core::{CoreManager, handle, tray},
logging, logging_error,
utils::logging::Type,
}; };
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use clash_verge_logging::{Type, logging, logging_error};
use smartstring::alias::String; use smartstring::alias::String;
use tauri::Emitter as _; use tauri::Emitter as _;

View File

@@ -1,9 +1,8 @@
use crate::{ use crate::{
config::{Config, IVerge}, config::{Config, IVerge},
core::handle, core::handle,
logging,
utils::logging::Type,
}; };
use clash_verge_logging::{Type, logging};
use std::env; use std::env;
use tauri_plugin_clipboard_manager::ClipboardExt as _; use tauri_plugin_clipboard_manager::ClipboardExt as _;

View File

@@ -1,8 +1,9 @@
use crate::config::Config; use crate::config::Config;
use crate::core::{CoreManager, handle, sysopt}; use crate::core::{CoreManager, handle, sysopt};
use crate::module::lightweight;
use crate::utils; use crate::utils;
use crate::utils::window_manager::WindowManager; use crate::utils::window_manager::WindowManager;
use crate::{logging, module::lightweight, utils::logging::Type}; use clash_verge_logging::{Type, logging};
/// Public API: open or close the dashboard /// Public API: open or close the dashboard
pub async fn open_or_close_dashboard() { pub async fn open_or_close_dashboard() {

View File

@@ -19,13 +19,13 @@ use crate::{
utils::{resolve, server}, utils::{resolve, server},
}; };
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use rust_i18n::i18n; use rust_i18n::i18n;
use tauri::{AppHandle, Manager as _}; use tauri::{AppHandle, Manager as _};
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use tauri_plugin_autostart::MacosLauncher; use tauri_plugin_autostart::MacosLauncher;
use tauri_plugin_deep_link::DeepLinkExt as _; use tauri_plugin_deep_link::DeepLinkExt as _;
use utils::logging::Type;
i18n!("locales", fallback = "zh"); i18n!("locales", fallback = "zh");
@@ -267,10 +267,9 @@ pub fn run() {
use crate::{ use crate::{
config::Config, config::Config,
core::{self, handle, hotkey}, core::{self, handle, hotkey},
logging,
process::AsyncHandler, process::AsyncHandler,
utils::logging::Type,
}; };
use clash_verge_logging::{Type, logging};
use tauri::AppHandle; use tauri::AppHandle;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
use tauri::Manager as _; use tauri::Manager as _;

View File

@@ -1,12 +1,12 @@
use crate::{ use crate::{
config::{Config, IVerge}, config::{Config, IVerge},
feat::create_local_backup_with_namer, feat::create_local_backup_with_namer,
logging,
process::AsyncHandler, process::AsyncHandler,
utils::{dirs::local_backup_dir, logging::Type}, utils::dirs::local_backup_dir,
}; };
use anyhow::Result; use anyhow::Result;
use chrono::Local; use chrono::Local;
use clash_verge_logging::{Type, logging};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::RwLock; use parking_lot::RwLock;
use std::{ use std::{

View File

@@ -1,12 +1,10 @@
use crate::{ use crate::{
config::Config, config::Config,
core::{handle, timer::Timer, tray::Tray}, core::{handle, timer::Timer, tray::Tray},
logging,
process::AsyncHandler, process::AsyncHandler,
utils::logging::Type,
}; };
use crate::logging_error; use clash_verge_logging::{Type, logging, logging_error};
use crate::utils::window_manager::WindowManager; use crate::utils::window_manager::WindowManager;
use anyhow::{Context as _, Result}; use anyhow::{Context as _, Result};

View File

@@ -4,7 +4,8 @@ use signal_hook::{
low_level, low_level,
}; };
use crate::{feat, logging, logging_error, utils::logging::Type}; use crate::feat;
use clash_verge_logging::{Type, logging, logging_error};
pub fn register() { pub fn register() {
tauri::async_runtime::spawn(async { tauri::async_runtime::spawn(async {

View File

@@ -8,7 +8,8 @@ use windows_sys::Win32::{
}, },
}; };
use crate::{core::handle, feat, logging, utils::logging::Type}; use crate::{core::handle, feat};
use clash_verge_logging::{Type, logging};
// code refer to: // code refer to:
// global-hotkey (https://github.com/tauri-apps/global-hotkey) // global-hotkey (https://github.com/tauri-apps/global-hotkey)

View File

@@ -1,7 +1,7 @@
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use crate::{logging, utils::logging::Type};
#[cfg(target_os = "windows")]
use anyhow::{Result, anyhow}; use anyhow::{Result, anyhow};
#[cfg(target_os = "windows")]
use clash_verge_logging::{Type, logging};
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
use std::{os::windows::process::CommandExt as _, path::Path, path::PathBuf}; use std::{os::windows::process::CommandExt as _, path::Path, path::PathBuf};

View File

@@ -1,10 +1,7 @@
use crate::{ use crate::core::{CoreManager, handle, manager::RunningMode};
core::{CoreManager, handle, manager::RunningMode},
logging,
utils::logging::Type,
};
use anyhow::Result; use anyhow::Result;
use async_trait::async_trait; use async_trait::async_trait;
use clash_verge_logging::{Type, logging};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
#[cfg(unix)] #[cfg(unix)]
use std::iter; use std::iter;

View File

@@ -1,5 +1,6 @@
use crate::{config::with_encryption, enhance::seq::SeqMap, logging, utils::logging::Type}; use crate::{config::with_encryption, enhance::seq::SeqMap};
use anyhow::{Context as _, Result, anyhow, bail}; use anyhow::{Context as _, Result, anyhow, bail};
use clash_verge_logging::{Type, logging};
use nanoid::nanoid; use nanoid::nanoid;
use serde::{Serialize, de::DeserializeOwned}; use serde::{Serialize, de::DeserializeOwned};
use serde_yaml_ng::Mapping; use serde_yaml_ng::Mapping;

View File

@@ -1,6 +1,4 @@
// #[cfg(not(feature = "tracing"))] // #[cfg(not(feature = "tracing"))]
#[cfg(not(feature = "tauri-dev"))]
use crate::utils::logging::NoModuleFilter;
use crate::{ use crate::{
config::{Config, IClashTemp, IProfiles, IVerge}, config::{Config, IClashTemp, IProfiles, IVerge},
constants, constants,
@@ -10,11 +8,13 @@ use crate::{
utils::{ utils::{
dirs::{self, PathBufExec as _, service_log_dir, sidecar_log_dir}, dirs::{self, PathBufExec as _, service_log_dir, sidecar_log_dir},
help, help,
logging::Type,
}, },
}; };
use anyhow::Result; use anyhow::Result;
use chrono::{Local, TimeZone as _}; use chrono::{Local, TimeZone as _};
#[cfg(not(feature = "tauri-dev"))]
use clash_verge_logging::NoModuleFilter;
use clash_verge_logging::Type;
use clash_verge_service_ipc::WriterConfig; use clash_verge_service_ipc::WriterConfig;
use flexi_logger::writers::FileLogWriter; use flexi_logger::writers::FileLogWriter;
use flexi_logger::{Cleanup, Criterion, FileSpec}; use flexi_logger::{Cleanup, Criterion, FileSpec};

View File

@@ -1,6 +1,5 @@
use crate::logging;
use crate::utils::logging::Type;
use anyhow::Result; use anyhow::Result;
use clash_verge_logging::{Type, logging};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::env; use std::env;
use std::fs; use std::fs;

View File

@@ -6,7 +6,6 @@ pub mod i18n;
pub mod init; pub mod init;
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub mod linux; pub mod linux;
pub mod logging;
pub mod network; pub mod network;
pub mod notification; pub mod notification;
pub mod resolve; pub mod resolve;

View File

@@ -1,8 +1,7 @@
#[cfg(target_os = "macos")] use clash_verge_logging::{Type, logging};
use crate::{logging, utils::logging::Type};
pub async fn set_public_dns(dns_server: String) { pub async fn set_public_dns(dns_server: String) {
use crate::utils::logging::Type; use crate::{core::handle, utils::dirs};
use crate::{core::handle, logging, utils::dirs};
use tauri_plugin_shell::ShellExt as _; use tauri_plugin_shell::ShellExt as _;
let app_handle = handle::Handle::app_handle(); let app_handle = handle::Handle::app_handle();

View File

@@ -9,11 +9,11 @@ use crate::{
sysopt, sysopt,
tray::Tray, tray::Tray,
}, },
logging, logging_error,
module::{auto_backup::AutoBackupManager, lightweight::auto_lightweight_boot, signal}, module::{auto_backup::AutoBackupManager, lightweight::auto_lightweight_boot, signal},
process::AsyncHandler, process::AsyncHandler,
utils::{init, logging::Type, server, window_manager::WindowManager}, utils::{init, server, window_manager::WindowManager},
}; };
use clash_verge_logging::{Type, logging, logging_error};
pub mod dns; pub mod dns;
pub mod scheme; pub mod scheme;

View File

@@ -8,9 +8,8 @@ use tauri::Url;
use crate::{ use crate::{
config::{Config, PrfItem, profiles}, config::{Config, PrfItem, profiles},
core::handle, core::handle,
logging,
utils::logging::Type,
}; };
use clash_verge_logging::{Type, logging};
pub(super) async fn resolve_scheme(param: &str) -> Result<()> { pub(super) async fn resolve_scheme(param: &str) -> Result<()> {
logging!(info, Type::Config, "received deep link: {param}"); logging!(info, Type::Config, "received deep link: {param}");

View File

@@ -6,7 +6,7 @@ use std::sync::{
}; };
use tokio::sync::Notify; use tokio::sync::Notify;
use crate::{logging, utils::logging::Type}; use clash_verge_logging::{Type, logging};
// 获取 UI 是否准备就绪的全局状态 // 获取 UI 是否准备就绪的全局状态
static UI_READY: AtomicBool = AtomicBool::new(false); static UI_READY: AtomicBool = AtomicBool::new(false);

View File

@@ -3,12 +3,9 @@ use tauri::WebviewWindow;
use crate::{ use crate::{
config::Config, config::Config,
core::handle, core::handle,
logging_error, utils::resolve::window_script::{INITIAL_LOADING_OVERLAY, WINDOW_INITIAL_SCRIPT},
utils::{
logging::Type,
resolve::window_script::{INITIAL_LOADING_OVERLAY, WINDOW_INITIAL_SCRIPT},
},
}; };
use clash_verge_logging::{Type, logging_error};
// 定义默认窗口尺寸常量 // 定义默认窗口尺寸常量
const DEFAULT_WIDTH: f64 = 940.0; const DEFAULT_WIDTH: f64 = 940.0;

View File

@@ -1,12 +1,12 @@
use super::resolve; use super::resolve;
use crate::{ use crate::{
config::{Config, DEFAULT_PAC, IVerge}, config::{Config, DEFAULT_PAC, IVerge},
logging, logging_error,
module::lightweight, module::lightweight,
process::AsyncHandler, process::AsyncHandler,
utils::{logging::Type, window_manager::WindowManager}, utils::window_manager::WindowManager,
}; };
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use clash_verge_logging::{Type, logging, logging_error};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use port_scanner::local_port_available; use port_scanner::local_port_available;

View File

@@ -47,9 +47,9 @@ macro_rules! singleton_with_logging {
pub fn global() -> &'static $struct_name { pub fn global() -> &'static $struct_name {
$instance_name.get_or_init(|| { $instance_name.get_or_init(|| {
let instance = Self::new(); let instance = Self::new();
$crate::logging!( clash_verge_logging::logging!(
info, info,
$crate::utils::logging::Type::Setup, clash_verge_logging::Type::Setup,
concat!($struct_name_str, " initialized") concat!($struct_name_str, " initialized")
); );
instance instance

View File

@@ -1,8 +1,5 @@
use crate::{ use crate::{core::handle, utils::resolve::window::build_new_window};
core::handle, use clash_verge_logging::{Type, logging};
logging,
utils::{logging::Type, resolve::window::build_new_window},
};
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use tauri::{Manager as _, WebviewWindow, Wry}; use tauri::{Manager as _, WebviewWindow, Wry};