#![allow(clippy::uninlined_format_args)]
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(feature = "simplelog")]
use {
crate::vprtln,
crate::V,
simplelog::{
ColorChoice, CombinedLogger, Config, LevelFilter, TermLogger, TerminalMode, WriteLogger,
},
std::fs::File,
std::sync::Once,
};
static DEBUG_LOG_ENABLED: AtomicBool = AtomicBool::new(false);
#[cfg(feature = "simplelog")]
static LOGGING_INIT: Once = Once::new();
#[allow(clippy::module_name_repetitions)]
pub fn enable_debug_logging() {
DEBUG_LOG_ENABLED.store(true, Ordering::SeqCst);
}
pub fn is_debug_logging_enabled() -> bool {
DEBUG_LOG_ENABLED.load(Ordering::SeqCst)
}
#[cfg(feature = "simplelog")]
pub fn configure_log() {
LOGGING_INIT.call_once(|| {
configure_simplelog();
});
vprtln!(V::V, "Initialized simplelog");
}
#[cfg(feature = "simplelog")]
fn configure_simplelog() {
if let Err(e) = CombinedLogger::init(vec![
TermLogger::new(
LevelFilter::Info,
Config::default(),
TerminalMode::Mixed,
ColorChoice::Auto,
),
WriteLogger::new(
LevelFilter::Debug,
Config::default(),
File::create("app.log").unwrap(),
),
]) {
eprintln!("Logger already initialized: {}", e);
}
}