Skip to content

Commit 372e267

Browse files
committed
examples: add renamed field to static/dynamic example
1 parent 9fcae78 commit 372e267

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/custom-static-and-dynamic-fields.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
55
fn main() {
66
let mut json_layer = fmt::layer()
77
.with_level(true)
8-
.with_thread_ids(true)
8+
// .with_thread_ids(true)
99
.with_file(true)
1010
.with_line_number(true)
1111
.with_target(false)
1212
.flatten_event(true);
1313

1414
let inner_layer = json_layer.inner_layer_mut();
15+
// Setting it inside the inner layer allows us to rename the field.
16+
inner_layer.with_thread_ids("thread_id");
17+
// This field will not change during the lifetime of the application.
1518
inner_layer.add_static_field("app", serde_json::Value::String("monitor".to_owned()));
19+
// This field might change (we might fork a subprocess or something)
1620
inner_layer.add_dynamic_field("pid", |_, _| {
1721
Some(serde_json::Value::Number(Number::from(std::process::id())))
1822
});
@@ -27,7 +31,7 @@ fn main() {
2731
// "level": "INFO",
2832
// "line_number": 24,
2933
// "pid": 3341821,
30-
// "threadId": "ThreadId(1)",
34+
// "thread_id": "ThreadId(1)",
3135
// "timestamp": "2025-06-23T20:04:51.512451Z",
3236
// "message": "Log with logger, app, and pid."
3337
// }

0 commit comments

Comments
 (0)