-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,7 +25,6 @@ use error::CliError; | |
| use std::{str::FromStr, sync::LazyLock}; | ||
| use tokio::sync::OnceCell; | ||
| use tracing::{debug, info, warn}; | ||
| use tracing_subscriber::EnvFilter; | ||
| use util::{data_dir, db_file, init_reports_dir}; | ||
|
|
||
| static DB: LazyLock<SqliteDb> = std::sync::LazyLock::new(|| { | ||
|
|
@@ -209,27 +208,42 @@ fn init_db(command: &ContenderSubcommand) -> Result<(), CliError> { | |
| } | ||
|
|
||
| fn init_tracing() { | ||
| let filter = EnvFilter::try_from_default_env().ok(); // fallback if RUST_LOG is unset | ||
| #[cfg(feature = "async-tracing")] | ||
| { | ||
| use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, Layer}; | ||
| let tokio_layer = console_subscriber::ConsoleLayer::builder() | ||
| .with_default_env() | ||
| .spawn(); | ||
| let fmt_layer = fmt::layer() | ||
| .with_ansi(true) | ||
| .with_target(true) | ||
| .with_line_number(true) | ||
| .with_filter(filter); | ||
|
|
||
| tracing_subscriber::Registry::default() | ||
| .with(fmt_layer) | ||
| .with(tokio_layer) | ||
| .init(); | ||
| use tracing_subscriber::{ | ||
| fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer, | ||
| }; | ||
|
|
||
| let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase(); | ||
| let debug_mode = rust_log.contains("=debug"); | ||
|
|
||
| let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")); | ||
|
|
||
| let fmt_layer = fmt::layer() | ||
| .with_ansi(true) | ||
| .with_target(debug_mode) | ||
| .with_line_number(debug_mode) | ||
| .with_file(debug_mode) | ||
| .with_filter(filter); | ||
|
|
||
| tracing_subscriber::registry().with(fmt_layer).init(); | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use temp_env::with_var; | ||
|
|
||
| #[test] | ||
| fn debug_mode_detected_from_rust_log() { | ||
| with_var("RUST_LOG", Some("contender=debug"), || { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase(); | ||
| assert!(rust_log.contains("=debug")); | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(not(feature = "async-tracing"))] | ||
| { | ||
| contender_core::util::init_core_tracing(filter); | ||
| #[test] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| fn info_mode_does_not_trigger_debug() { | ||
| with_var("RUST_LOG", Some("contender=info"), || { | ||
| let rust_log = std::env::var("RUST_LOG").unwrap_or_default().to_lowercase(); | ||
| assert!(!rust_log.contains("=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.
we still need the
async-tracingconditional, looks like it was just removed...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.
Ah, that’s on me. I accidentally dropped the
#[cfg(feature = "async-tracing")]guard when refactoringinit_tracing(). Sorry about the oversight.