use once_cell::sync::OnceCell;
use tracing::dispatcher;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LoggingMode {
Library,
Application,
}
pub struct SubscriberDetector;
static DETECTED_MODE: OnceCell<LoggingMode> = OnceCell::new();
impl SubscriberDetector {
#[inline]
pub fn has_subscriber() -> bool {
dispatcher::has_been_set()
}
pub fn detect_mode() -> LoggingMode {
*DETECTED_MODE.get_or_init(|| {
if Self::has_subscriber() {
LoggingMode::Library
} else {
LoggingMode::Application
}
})
}
}