Skip to main content

stdout/
stdout.rs

1//! Pretty stdout example. Mirrors the demo from `tracing-systemd` 0.1's
2//! `test_log_stdout` but uses the new builder API.
3//!
4//! Run with: `cargo run --example stdout`
5//! Or with `NO_COLOR=1 cargo run --example stdout` to verify auto color
6//! detection.
7
8use tracing::{debug, error, info, instrument, trace, warn};
9use tracing_subscriber::prelude::*;
10use tracing_systemd::SystemdLayer;
11
12fn main() {
13    tracing_subscriber::registry()
14        .with(
15            SystemdLayer::stdout()
16                .with_target(true)
17                .with_thread_ids(true)
18                .with_level_prefix(false),
19        )
20        .init();
21
22    root_log_fn(true);
23}
24
25#[instrument(fields(outside_instrument_field = true))]
26fn root_log_fn(_param: bool) {
27    info!("Root log");
28    inner_log_1(true);
29}
30
31#[instrument(fields(inside_instrument_field = true))]
32fn inner_log_1(_inside_parameter_field: bool) {
33    trace!("this is a trace");
34    debug!(field_in_function = "also works");
35    info!("this is an info log");
36    warn!("Inner log 1");
37    error!("this is an error");
38}