-
Notifications
You must be signed in to change notification settings - Fork 16
Fix RUST_LOG implementation by using default directive #331
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
Merged
+8
−12
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66923e5 to
1513a66
Compare
|
Code coverage summary for 5b3ab7e: ✅ Region coverage 67% passes |
The issue was using EnvFilter::builder().from_env() which returns Ok even when RUST_LOG is unset, preventing the unwrap_or_else fallback from executing. This meant whatever fallbacks we had were ignored. Using default directive solves this and yields nicer code.
1513a66 to
5b3ab7e
Compare
kp-mariappan-ramasamy
approved these changes
Dec 16, 2025
Contributor
kp-mariappan-ramasamy
left a comment
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.
LGTM. Thanks for fixing
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The issue was using
EnvFilter::builder().from_env()which returnsOkeven whenRUST_LOGis unset, preventing theunwrap_or_elsefallback from executing. This meant whatever fallback settings we had were ignored.Changed to usetry_from_env()instead, which properly returnsErrwhenRUST_LOGis not set, allowing theunwrap_or_elsefallback to useconfig.log_level(from CLI args, env vars, or config file).From docs on
from_env, it will use a "error" default when seeing unset/empty env var:And from docs on
try_from_env, it will give anErrwhen seeing unset env var:Edit: a even nicer approach is to use default directive, eliminating the extra
unwrap_or_else.Thanks to #322 for the pointers.
Motivation and Context
How Has This Been Tested?
Types of changes
Checklist:
main