From eaff14da5f1318d9867b08c3cb3ede34a33e2ec3 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Sun, 12 Feb 2023 23:32:26 +0300 Subject: [PATCH] [proxy] Restore INFO as the default tracing level Also move tracing init to its own function. --- proxy/src/main.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/proxy/src/main.rs b/proxy/src/main.rs index 8bf81ee2b7..8812f77b62 100644 --- a/proxy/src/main.rs +++ b/proxy/src/main.rs @@ -41,13 +41,8 @@ async fn flatten_err( #[tokio::main] async fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt() - .with_ansi(atty::is(atty::Stream::Stdout)) - .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) - .with_target(false) - .init(); - - // initialize sentry if SENTRY_DSN is provided + // First, initialize logging and troubleshooting subsystems. + init_tracing(); let _sentry_guard = init_sentry(Some(GIT_VERSION.into()), &[]); info!("Version: {GIT_VERSION}"); @@ -112,6 +107,21 @@ async fn main() -> anyhow::Result<()> { Ok(()) } +/// Tracing is used for logging and telemetry. +fn init_tracing() { + tracing_subscriber::fmt() + .with_env_filter({ + // This filter will examine the `RUST_LOG` env variable. + use tracing_subscriber::filter::{EnvFilter, LevelFilter}; + EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy() + }) + .with_ansi(atty::is(atty::Stream::Stdout)) + .with_target(false) + .init(); +} + /// ProxyConfig is created at proxy startup, and lives forever. fn build_config(args: &clap::ArgMatches) -> anyhow::Result<&'static ProxyConfig> { let tls_config = match (