pub mod logger;
pub mod formatter;
pub mod uid;
#[cfg(feature = "kv")]
pub mod kv;
#[cfg(feature = "rolling")]
pub mod rolling;

use std::sync::{Arc, RwLock};
use log::SetLoggerError;
use crate::logger::{Dispatch, LogHandle, Logger};

pub fn init(initial_logger: impl Dispatch + 'static) -> Result<LogHandle, SetLoggerError> {
    let level = initial_logger.max_level();
    let logger = Arc::new(RwLock::new(Logger::new(
        level,
        vec![Box::new(initial_logger)]
    )));
    log::set_max_level(level);
    let log_wrapper = LogHandle(logger);
    log::set_boxed_logger(Box::new(log_wrapper.clone()))?;
    Ok(log_wrapper)
}