ensure_test_logging

Function ensure_test_logging 

Source
pub fn ensure_test_logging(default_level: Option<Level>)
Expand description

Safe logging initialization for tests - can be called multiple times without crashing

This function provides a safe way for tests to enable logging without worrying about whether a tracing subscriber has already been initialized. It uses std::sync::Once to ensure initialization happens only once per test process.

Features:

  • Console-only output (no file logging for tests)
  • DEBUG level by default, but respects RUST_LOG environment variable
  • Can be called from any test file safely
  • Idempotent - multiple calls are safe and efficient

§Usage

use edb_common::logging;
use tracing::info;

#[test]
fn my_test() {
    logging::ensure_test_logging();
    info!("This will work safely in any test!");
    // ... rest of test
}