tracing-subscribe是tracing的结构化日志的实现,所以为了使用tracing一般都需要引入tracing-subscriber依赖 使用tracing前,需要进行配置与初始化 为了能够进行灵活的配置与扩展,tracing-subscribe提供了Layer抽象,通过添加层来进行配置tracing 首先通过tracing_subscriber::registry()创建 "注册表",然后可通过with不断去添加层,最...
use tracing::info;use tracing_subscriber;fn main() { // 初始化全局 Collector tracing_subscriber::fmt::init(); info!("Hello, world!");} 运行上面这段代码,可以在终端中看到一条 INFO 级别的事件,如果需要将 Trace 信息发送到其他地方,就要用到其他的 Collector 实现,比如 tracing-appender...
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt}; fn main() { tracing_subscriber::registry().with(fmt::layer()).init(); // 在 span 的上下文之外记录一次 event 事件 event!(Level::INFO, "something happened"); let span = span!(Level::INFO, "my_span"); let...
rust 如何根据条件向tracing_subscriber的注册表添加层?Option<Layer>实现了Layer,所以正确的方法是使用...
我想使用字符串设置跟踪级别(因为我从环境变量获取级别)。 let env_log_level = std::env::var("LOG_LEVEL").unwrap(); tracing_subscriber::fmt() .with_max_level(tracing::Level::DEBUG)// somehow use env_log_level here.with_target(false) ...
rust 如何使用tracing-subscriber设置自定义时间戳格式?"[year]-[month padding:zero]-[day padding:...
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 专为性能而设计,使用它不应当明显影响您的应用性能。为了最小化性能影响,我...
rust 如何使用tracing-subscriber设置自定义时间戳格式?"[year]-[month padding:zero]-[day padding:...
tracing_subscriber::fmt() .with_env_filter(EnvFilter::from( "warn,actix_web1=debug,nacos_rust_client=info", ))//这里可以自定义某些第三方库的日志是否打印,第一个是全局日志等级,后面的是自定义包 .with_line_number(true)//显示行数 .with_thread_ids(true)//显示线程id ...
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 ...