feat: add tracing support to logger initialization (#5120)

This commit is contained in:
Tunglies
2025-10-18 22:57:51 +08:00
committed by GitHub
Unverified
parent 385ffafc67
commit a60cab989d
2 changed files with 12 additions and 3 deletions

View File

@@ -127,6 +127,7 @@ verge-dev = ["clash_verge_logger/color"]
tauri-dev = []
tokio-trace = ["console-subscriber"]
clippy = ["tauri/test"]
tracing = []
[[bench]]
name = "draft_benchmark"

View File

@@ -1,3 +1,4 @@
#[cfg(not(feature = "tracing"))]
#[cfg(not(feature = "tauri-dev"))]
use crate::utils::logging::NoModuleFilter;
use crate::{
@@ -38,7 +39,13 @@ pub async fn init_logger() -> Result<()> {
};
let log_dir = dirs::app_logs_dir()?;
let spec = LogSpecBuilder::new().default(log_level).build();
let mut spec = LogSpecBuilder::new();
spec.default(log_level);
#[cfg(feature = "tracing")]
spec.module("tauri", log::LevelFilter::Debug);
#[cfg(feature = "tracing")]
spec.module("wry", log::LevelFilter::Debug);
let spec = spec.build();
let logger = Logger::with(spec)
.log_to_file(FileSpec::default().directory(log_dir).basename(""))
@@ -52,8 +59,9 @@ pub async fn init_logger() -> Result<()> {
format: "%Y-%m-%d_%H-%M-%S",
},
Cleanup::KeepLogFiles(log_max_count),
)
.filter(Box::new(NoModuleFilter(&["wry", "tauri"])));
);
#[cfg(not(feature = "tracing"))]
let logger = logger.filter(Box::new(NoModuleFilter(&["wry", "tauri"])));
let _handle = logger.start()?;