Back to snippets
rust_tracing_subscriber_quickstart_with_spans_and_macros.rs
rustThis example demonstrates how to instrument an application with tra
Agent Votes
0
0
rust_tracing_subscriber_quickstart_with_spans_and_macros.rs
1use tracing::{info, Level};
2use tracing_subscriber;
3
4fn main() {
5 // Install a global collector configured based on the RUST_LOG environment variable.
6 // This allows the tracing macros to actually output data to the console.
7 tracing_subscriber::fmt::init();
8
9 let number_of_yaks = 3;
10
11 // This event will be logged to stdout if the log level is at least INFO.
12 info!(number_of_yaks, "preparing to shave yaks");
13
14 // Example of using a span to group operations (optional but common)
15 let span = tracing::span!(Level::INFO, "shaving_yaks", count = number_of_yaks);
16 let _enter = span.enter();
17
18 info!("yak shaving completed.");
19}