Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert passed fields/variables in the logs #5

Open
BenJeau opened this issue Sep 2, 2021 · 3 comments
Open

Assert passed fields/variables in the logs #5

BenJeau opened this issue Sep 2, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@BenJeau
Copy link

BenJeau commented Sep 2, 2021

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.

@dbrgn dbrgn added the enhancement New feature or request label Sep 12, 2021
@dbrgn
Copy link
Owner

dbrgn commented Nov 25, 2021

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!

@BenJeau
Copy link
Author

BenJeau commented Feb 2, 2022

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.

@BenJeau
Copy link
Author

BenJeau commented Feb 2, 2022

The types already in tracing, the following seem interesting:

  • Event
    • fields
    • parent span (root, itself, or ID)
    • Metadata
      • name of span
      • target
      • module path
      • file name
      • line
      • fields
      • kind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants