tracing
tracing copied to clipboard
Possibility to override default fields name with JSON formatter
Feature Request
Crates
tracing-subscriber
Motivation
I wanted to update the fields name of the JSON subscriber to mimic the ones produced by other internal services. At the end, all the logs are retrieved by fluent bit, and I wanted to simplify the aggregation of our system logs.
If I'm doing the solution proposed below, it has currently no impact.
Proposal
let formatter = format::debug_fn(|writer, field, value| {
match field.name() {
"target" => write!(writer, "my_field: {:?}", value),
_ => write!(writer, "{}: {:?}", field, value)
}
})
.delimited(", ");
let subscriber = tracing_subscriber::fmt()
.with_max_level(Level::INFO)
.json()
.flatten_event(true)
.fmt_fields(formatter)
.finish();
tracing::subscriber::set_global_default(subscriber)
.with_context(|| "Failed to initialize the logging library")?;
Alternatives
I could reimplement the serializer to customize it as I would like to be, but that's not the best solution. And it can be hard to maintain across tracing releases.
Greetings!
@hawkw Any update on this? Faced with same problem and implementing own Json-Layer is super counterproductive.
@BratSinot I don't think anyone is actively working on this, but we'd be glad to accept PRs