-
Notifications
You must be signed in to change notification settings - Fork 38
Fix/403/log debug sources #405
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
Fix/403/log debug sources #405
Conversation
- parse RUST_LOG env var and normalize to lowercase
- detect debug mode by checking for any substring matching `=debug`
- construct EnvFilter from RUST_LOG with fallback to "info" if unset
- configure tracing_subscriber::fmt::Layer with conditional toggles:
* with_file(true/false)
* with_line_number(true/false)
* with_target(true/false)
- registry initialized with fmt_layer to apply formatting globally
Implements enhancement requested in flashbots#403
- add temp-env as a dev-dependency
- add #[cfg(test)] module in crates/cli/src/main.rs
- use temp_env::with_var to set RUST_LOG temporarily
- verify debug mode detection logic:
* RUST_LOG="contender=debug" → assert contains("=debug")
* RUST_LOG="contender=info" → assert !contains("=debug")
- ensures environment isolation between tests without global state
leakage
Adds test case for the enhancement implemented in flashbots#403
- add entry under Unreleased in crates/cli/CHANGELOG.md - add corresponding summary under Unreleased in root CHANGELOG.md Adds changelog entries for enhancement implemented in flashbots#403
zeroXbrock
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.
thanks for the quick turnaround @LilSuperUser, left a few comments
| #[cfg(not(feature = "async-tracing"))] | ||
| { | ||
| contender_core::util::init_core_tracing(filter); | ||
| #[test] |
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.
same as below, we don't need to test the functionality of an external crate ourselves
|
|
||
| #[test] | ||
| fn debug_mode_detected_from_rust_log() { | ||
| with_var("RUST_LOG", Some("contender=debug"), || { |
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.
I don't think this test is really necessary, all it does is test the with_var function.
|
|
||
| fn init_tracing() { | ||
| let filter = EnvFilter::try_from_default_env().ok(); // fallback if RUST_LOG is unset | ||
| #[cfg(feature = "async-tracing")] |
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.
we still need the async-tracing conditional, looks like it was just removed...
|
closing in favor of #406 |
Motivation (#403)
The CLI’s tracing output was previously verbose, always including file, line, and target information regardless of log level. This added noise for normal usage at
infolevel.We wanted to improve UX by showing full source context only when explicitly running in debug mode.
Additionally, the detection logic for debug mode (
contains("=debug")) is custom, so it requires test coverage to ensure correctness.Finally, changelogs needed to be updated to reflect the enhancement and its associated tests.
Solution
Logging enhancement
RUST_LOGenv var and normalize to lowercase.=debug.EnvFilterfromRUST_logwith fallback to"info"if unset.tracing_subscriber::fmt::Layerwith conditional toggles:with_file(true/false)with_line_number(true/false)with_target(true/false)Scoped test case
temp-envas a dev-dependency.moduele incrates/cli/src/main.rs`.temp_env::with_varto setRUST_LOGtemp in each test scope.RUST_LOG="contender=debug"→debug_modeistrue.RUST_LOG="contender=info"→debug_modeisfalse.PR Checklist
cargo +nightly clippy --workspace --lib --examples --tests --benches --all-features --locked --fixcargo fmt --allCHANGELOG.mdin each affected crate