diff --git a/.gitignore b/.gitignore index f4ad7734..dfbc7a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ Cargo.lock *.iml .vscode/ info.log +log/ + diff --git a/src/config/mod.rs b/src/config/mod.rs index 6760bb72..d2bd74a6 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -49,11 +49,11 @@ pub fn init_config_with_err_handler( log::set_boxed_logger(Box::new(logger)).map(|()| handle) } -/// Initializes the global logger as a log4rs logger using the provided raw config. +/// Create a log4rs logger using the provided raw config. /// -/// This will return errors if the appenders configuration is malformed or if we fail to set the global logger. +/// This will return errors if the appenders configuration is malformed. #[cfg(feature = "config_parsing")] -pub fn init_raw_config(config: RawConfig) -> Result<(), InitError> { +pub fn create_raw_config(config: RawConfig) -> Result { let (appenders, errors) = config.appenders_lossy(&Deserializers::default()); if !errors.is_empty() { return Err(InitError::Deserializing(errors)); @@ -63,7 +63,15 @@ pub fn init_raw_config(config: RawConfig) -> Result<(), InitError> { .loggers(config.loggers()) .build(config.root())?; - let logger = crate::Logger::new(config); + Ok(crate::Logger::new(config)) +} + +/// Initializes the global logger as a log4rs logger using the provided raw config. +/// +/// This will return errors if the appenders configuration is malformed or if we fail to set the global logger. +#[cfg(feature = "config_parsing")] +pub fn init_raw_config(config: RawConfig) -> Result<(), InitError> { + let logger = create_raw_config(config)?; log::set_max_level(logger.max_log_level()); log::set_boxed_logger(Box::new(logger))?; Ok(()) diff --git a/src/config/raw.rs b/src/config/raw.rs index e3f9a596..cd1d951f 100644 --- a/src/config/raw.rs +++ b/src/config/raw.rs @@ -524,6 +524,7 @@ loggers: let config_str = sample_file[config_start..config_end].trim(); let config = ::serde_yaml::from_str::(config_str); - assert!(config.is_ok()) + assert!(config.is_ok()); + assert!(config::create_raw_config(config.unwrap()).is_ok()); } }