-
Notifications
You must be signed in to change notification settings - Fork 50
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
chore: set logger without mucking around with env vars #503
base: main
Are you sure you want to change the base?
chore: set logger without mucking around with env vars #503
Conversation
}); | ||
let _guard = tracing_subscriber::fmt() | ||
.with_env_filter("debug") | ||
.with_test_writer() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html#method.with_test_writer for why this is useful in tests.
What problem are you trying to fix? |
I hit a panic when trying to use I figured that setting the env var and using a |
This is tailored to my workflow. My requirements are:
With 1, this is what I expect.
This PR seem to not have any reasonable defaults. |
cargo's default behaviour is to not show logs if the test is passing. To override that, you need to pass I did notice that RA didn't show me all usages of If you don't want the |
Fully aware of all that. And no, I don't want to write |
We can remove I would like to understand the reasoning though. In what scenario do you need to see the output of a passing test? |
Many times when I use the integration tests, it's to follow a flow of events happening. My use case is not necessarily a pass/fail check, it's figuring out what's going on using an integration test as reproduction. This is different to unit tests, where there pretty much always is a pass/fail and I have no need to see logs for that. |
Env vars are global to a process. Setting them from within the tests is problematic because those tests are run concurrently in the same process.
tracing
allows us to set a logger for the current stack scope usingset_default
. Instead of fighting over which test should initialize the logger, we can only set it for the current scope of each test.