diff --git a/test_helpers/Cargo.toml b/test_helpers/Cargo.toml index 8e00327825..a8c1a55a1f 100644 --- a/test_helpers/Cargo.toml +++ b/test_helpers/Cargo.toml @@ -9,3 +9,4 @@ dotenv = "0.15.0" env_logger = "0.7.1" tempfile = "3.1.0" tracing = "0.1" + diff --git a/test_helpers/src/lib.rs b/test_helpers/src/lib.rs index 67f36ec51b..12b0cf517f 100644 --- a/test_helpers/src/lib.rs +++ b/test_helpers/src/lib.rs @@ -6,7 +6,10 @@ clippy::use_self )] -use std::{env, f64, sync::Arc}; +use std::{ + env, f64, + sync::{Arc, Once}, +}; pub use tempfile; pub mod tracing; @@ -80,9 +83,17 @@ pub fn tag_key_bytes_to_strings(bytes: Vec) -> String { } } +static LOG_SETUP: Once = Once::new(); + +/// Enables debug logging. This function can be called more than once pub fn enable_logging() { - std::env::set_var("RUST_LOG", "debug"); - env_logger::init(); + // ensure the global has been initialized + LOG_SETUP.call_once(|| { + // TODO honor any existing RUST_LOG level (and maybe not start + // logging unless it is set??) + std::env::set_var("RUST_LOG", "debug"); + env_logger::init(); + }) } #[macro_export]