我是 Rust 新手。我尝试使用axum和跟踪框架来制作一个Web程序。当我使用tracing并发送请求时,会有hyper log输出。如何过滤掉这些日志并保留我的应用程序本身的日志?
我的代码:
let filter: EnvFilter = "hyper=debug".parse().expect("filter should parse");
let logger = Registry::default()
.with(EnvFilter::from_default_env().add_directive(log_env.into()).with_filter(filter))
.with(fmt::Layer::default().event_format(format))
;
tracing::subscriber::set_global_default(logger).unwrap();
但不适合我
在你的
Cargo.toml
tracing-subscriber = {version="0.3", features=["env-filter"]}
在你的代码中:
tracing_subscriber::fmt::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
然后:
RUST_LOG=my_crate=DEBUG cargo run