Closed ahmed-said-jax closed 1 week ago
Update: I was being dumb. I tried deriving Valuable
on the struct, but it was resulting in stringified output, rather than JSON, leading to me creating this issue. I realized I hadn't turned on the valuable
feature of both the tracing
and tracing-subscriber
crates.
To achieve what basically what I want, I just need:
tracing::error!(some_struct = some_struct.as_value())
Feature Request
I'm not sure how hard this would be, and I think others have brought up adjacent issues, but I really think it would be valuable (pun intended) to be able to log any type implementing
Serialize
as JSON the wayserde_json
would output it, usinglog
s key-value feature.Motivation
I have custom error types in my application that allow me to use other tools to analyze errors programmatically. If these could be natively logged using
tracing
, rather than me writing the output to a JSON file, it save lots of complexity.Here's what I want to be able to do:
ideally, running this would give me the following (pretty-printed for readibility):
right now,
tracing-subscriber
just ignoressome_struct
, printing the same as above without the"some_struct"
object.Proposal
Unfortunately, I'm not familiar enough with the workings of the
tracing
ecosystem to provide any valuable ideas at the moment, but I'm happy to try if this is a good idea.