This repository was archived by the owner on Oct 10, 2023. It is now read-only.
Add --debug flag which sets the log level to debug#146
Merged
Conversation
This will print out additional debug logging. It also displays the telemetry that was sent (if it was sent).
Hoverbear
reviewed
Sep 28, 2022
Contributor
There was a problem hiding this comment.
I would prefer it if --debug added a Directive (https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives) of riff=debug without harming other portions of the RUST_LOG which may exist.
This is so a user could still do like RUST_LOG=mio=trace riff --debug.
I used to do this like
pub(crate) fn filter_layer(&self) -> eyre::Result<EnvFilter> {
let mut filter_layer = match EnvFilter::try_from_default_env() {
Ok(layer) => layer,
Err(e) => {
// Catch a parse error and report it, ignore a missing env.
if let Some(source) = e.source() {
match source.downcast_ref::<std::env::VarError>() {
Some(std::env::VarError::NotPresent) => (),
_ => return Err(e).wrap_err_with(|| "parsing RUST_LOG directives"),
}
}
EnvFilter::try_new(&format!("{}={}", env!("CARGO_PKG_NAME"), self.log_level()))?
},
};
for directive in &self.log_level {
// 'clone' the directive. (PR: https://github.com/tokio-rs/tracing/pull/1985)
let directive_str = directive.to_string();
let directive = Directive::from_str(&directive_str)?;
filter_layer = filter_layer.add_directive(directive);
}
Ok(filter_layer)
}Where this was some arg in the clap struct:
/// Tracing directives
///
/// This application also understands the `RUST_LOG` environment variable.
///
/// See https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives
#[clap(long, global = true, group = "verbosity", multiple_occurrences = true)]
pub(crate) log_level: Vec<Directive>,However that was for random hobby stuff, so we may want some different behavior.
This allows other RUST_LOG directives to take effect (e.g. `RUST_LOG=mio=trace`).
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This will print out additional debug logging. It also displays the telemetry that was sent (if it was sent).
Just gotta add a directive for us (and only us) that will override the "default" of--debugtakes precedence over theRUST_LOGenv var, but I don't know of a good way to communicate this happens because, well, tracing hasn't been set up yet...info! Thanks, Ana!