Created
December 15, 2020 11:30
-
-
Save UsairimIsani/db6a6c951e82ecb88b3bf632a3ae674a to your computer and use it in GitHub Desktop.
This file contains 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
// For tests, we only initialize logging once. | |
#[cfg(test)] | |
use std::sync::Once; | |
#[cfg(test)] | |
static LOGGER_INIT: Once = Once::new(); | |
// Rust runs the tests concurrently, so unless we synchronize logging access | |
// it will crash when attempting to run `cargo test` with some logging facilities. | |
#[cfg(test)] | |
pub fn ensure_env_logger_initialized() { | |
use std::io::Write; | |
LOGGER_INIT.call_once(|| { | |
let mut builder = env_logger::Builder::from_default_env(); | |
builder | |
.format(|buf, record| writeln!(buf, "[{}] - {}", record.level(), record.args())) | |
.init(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment