use std::str::FromStr; use log::LevelFilter; use simple_logger::SimpleLogger; pub fn load_settings(config_name: &str, env_prefix: &str) -> T where for<'de> T: serde::Deserialize<'de>, { let default_file = config::File::with_name(&format!("emgauwa-{}", config_name)).required(false); config::Config::builder() .add_source(default_file) .add_source( config::Environment::with_prefix(&format!("EMGAUWA_{}", env_prefix)) .prefix_separator("__") .separator("__"), ) .build() .expect("Error building settings") .try_deserialize::() .expect("Error reading settings") } pub fn init_logging(level: &str) { let log_level: LevelFilter = LevelFilter::from_str(level).expect("Error parsing log level."); log::trace!("Log level set to {:?}", log_level); SimpleLogger::new() .with_level(log_level) .init() .expect("Error initializing logger."); }