Search code examples
rustrust-tracing

How can I rename fields with the builtin json tracing subscriber?


The tracing json subscriber gives the following stdout out of the box:

fn main() {
    tracing_subscriber::fmt()
        .json()
        .with_max_level(tracing::Level::DEBUG)
        .flatten_event(true)
        .init();

    tracing::debug!("This is a debug message");
}
{"timestamp":"2023-07-14T20:47:29.302872Z","level":"DEBUG","message":"This is a debug message","target":"publisher"}

How can I rename the field "level" to "severity"?

I tried to use the fmt::format::debug_fn but it doesn't seem to be compatible.


Solution

  • The name "level" is hardcoded into tracing-subscriber, so I don't think you can change it without writing your own implementation of FormatEvent.