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

Add log level override via RUST_LOG environment variable #145

Merged
merged 5 commits into from
Aug 25, 2021

Conversation

XA21X
Copy link
Member

@XA21X XA21X commented Aug 23, 2021

For ad-hoc testing and when writing tests, it is convenient to be able to override the log level without changing code or config. This is a common use case that will hopefully be supported by upstream in the future - see tokio-rs/tracing#1466.

Example usage:

RUST_LOG=debug,shotover-proxy=trace shotover-proxy [...]

@rukai rukai assigned rukai and unassigned rukai Aug 23, 2021
@rukai rukai self-requested a review August 23, 2021 01:29
Copy link
Member

@rukai rukai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for splitting it out!
This change makes sense to me.

Just a few requests.

shotover-proxy/src/runner.rs Outdated Show resolved Hide resolved
shotover-proxy/src/runner.rs Outdated Show resolved Hide resolved
@rukai
Copy link
Member

rukai commented Aug 23, 2021

It seems try_new error message is worse than new.
We now only get Error: invalid filter directive
But we used to get: ignoring `blah=blah`: invalid filter directive

We can improve it with:

EnvFilter::try_new(&directives).map_err(|x| anyhow!("{}: {}", x, directives))?

We can then further improve it by using the add_directive API which lets us fail on the directives individually and then we can report which directive source specifically caused the issue.
https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/filter/struct.EnvFilter.html#method.add_directive
Feel free to do just the first solution or both solutions, up to you.

Copy link
Member

@rukai rukai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, a unittest as well!

@XA21X
Copy link
Member Author

XA21X commented Aug 24, 2021

Pending second review @benbromhead?, thanks

@XA21X XA21X linked an issue Aug 24, 2021 that may be closed by this pull request
@rukai rukai merged commit 3391ea3 into main Aug 25, 2021
@XA21X XA21X deleted the env-log-level-override branch September 2, 2021 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants