What I need is a JSON formatter that prints logs in a custom JSON schema / struct format.

There are some mandatory fields that should be set initially (e.g. environment such as test, prod) and printed out with every log entry without the need of specifying it in every log call (such as info!("..")) call. Some other fields are optional. Could I include optional fields with info!(key=value) ?

I need some guidance how I should implement that. Is it a good idea to copy tracing's JSON Formatter (quite a bunch of code) and align it to my custom data structure or should I rather use a Layer (on top of the JSON Formatter?)?

Thanks for your input


Just found a related issue https://github.com/tokio-rs/tracing/issues/2391

© 2022 pullanswer.com - All rights reserved.