-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize.rs
25 lines (22 loc) · 1.07 KB
/
customize.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use tracing_subscriber::prelude::*;
fn main() {
let subscriber = tracing_subscriber::registry().with(
tracing_ndjson::builder()
.with_level_name("severity")
.with_level_value_casing(tracing_ndjson::Casing::Uppercase)
.with_timestamp_name("ts")
.with_timestamp_format(tracing_ndjson::TimestampFormat::UnixMillis)
.with_message_name("msg")
.with_line_numbers(true)
.with_file_names(true)
.layer(),
);
tracing::subscriber::set_global_default(subscriber).unwrap();
tracing::info!(life = 42, "Hello, world!");
// {"life":42,"msg":"Hello, world!","target":"customize","ts":1697836630814,"file":"examples/customize.rs","line":17,"severity":"INFO"}
let span = tracing::info_span!("hello", "request.uri" = "https://example.com");
span.in_scope(|| {
tracing::info!("Hello, world!");
// {"severity":"INFO","target":"customize","file":"examples/customize.rs","msg":"Hello, world!","ts":1697836630814,"line":22,"request.uri":"https://example.com"}
});
}