("done with expensive work");}fn main() { tracing_subscriber::fmt() // enable everything .with_max_level(tracing::Level::TRACE) // sets this to be the default, global collector for this application. .init(); let span = info_span!("root"); let _enter = span...
Level接受“错误”、“警告”、“信息”、“调试”或“跟踪”(不区分大小写)。所以你可以像这样使用它: usestd::str::FromStr; let env_log_level = std::env::var("LOG_LEVEL").unwrap(); tracing_subscriber::fmt() .with_max_level(Level::from_str(&env_log_level).unwrap()) .with_target(fal...
使用tracing_subscriber::filter::Targets 优化目标过滤: use tracing_subscriber::filter::Targets; fn main() { let targets = Targets::new() .with_target("my_crate", LevelFilter::INFO) .with_target("other_crate", LevelFilter::WARN); let subscriber = tracing_subscriber::registry() .with(target...
tracing_subscriber::filter::LevelFilter设置级别过滤器 可以根据日志级别进行过滤,减少不必要的事件处理 示例代码: use tracing_subscriber::filter::LevelFilter; fn main() { let subscriber = tracing_subscriber::fmt() .with_max_level(LevelFilter::INFO) .finish(); tracing::subscriber::set_global_defau...
rust 如何将String转换为要与tracing_subscriber一起使用的Level?Level实现了FromStr,它接受“error”、...
rust 如何将String转换为要与tracing_subscriber一起使用的Level?Level实现了FromStr,它接受“error”、...
use tracing::info; use tracing_subscriber; fn main { tracing_subscriber::fmt::init; info!("this is an informational message"); perform_complex_operation; } fn perform_complex_operation { //... } 提高性能的策略 Tracing 专为性能而设计,使用它不应当明显影响您的应用性能。为了最小化性能影响,我...
Finally, in some cases, it may be useful to combine multiple different ways of recording traces together to build a single Subscriber that implements multiple behaviors. For this purpose, the tracing-subscriber crate provides a Layer trait that represents a component that may be composed together ...
| the static maximum level is INFO. note: to enable debug logging, do not enable the `max_level_info` feature The alternative would be to implement this behavior intracing-core, when processing themax level hintsprovided by the subscriber(s). This would have the advantage of working "out ...
(Level::INFO,"handle_client")).await.unwrap_or_else(|e| error!("error: {:?}", e));});}Ok(())}#[tokio::main]asyncfnmain()->Result<(),Box<dyn std::error::Error>>{ tracing_subscriber::fmt::init(); info!("starting server");run_server().await?;Ok(())}在这个示例...