tracing-test
tracing-test copied to clipboard
Assert passed fields/variables in the logs
I'm looking into asserting the recorded fields from tracing. It doesn't seem like this testing lib supports it (please correct me if I'm wrong).
Also, please let me know if you would be open to a PR adding this functionality, if you think it would be useful for others - I may dive into this lib and add that feature.
Yes, you're right, I think this is not currently supported.
Right now the subscriber simply writes bytes to a Vec writer, and the default output doesn't contain recorded fields I think. I'm not 100% sure about how the recorded fields are implemented, but I assume that the subscriber is responsible for formatting these logs and fields, right?
So what we could do is encoding the logs into a serialized format, and then the assertion functions would decode the lines again into a LogCall or LogLine struct. Or maybe it could even be decoded into the type that tracing uses internally to store the logs.
That was just a quick brainstorming. A pull request - or even just a comment with a concrete proposal - would be welcome!
I'm searching online and it seems like you can get more data with layers from tracing, like here https://burgers.io/custom-logging-in-rust-using-tracing - although it would require a bit of rewrite, at least for the subscriber.rs.