//! This is a minimal example with a config file and logging #[macro_use] extern crate serde_derive; #[macro_use] extern crate log; use clappconfig::AppConfig; // Must be in scope so the trait methods may be used #[derive(Serialize, Deserialize, Debug, Default)] #[serde(default)] struct Config { foo: u32, bar: u32, } impl AppConfig for Config { // We want init() to just return the config struct type Init = Config; /// Logging - we do not have a config option for this, so just return a default value fn logging(&self) -> &str { "info" } /// Finalize config (this is called inside `init()`) fn configure<'a>(self, _clap: &clap::ArgMatches<'a>) -> anyhow::Result { Ok(self) } } fn main() -> anyhow::Result<()> { let cfg = Config::init("Foo Example", "examples/foo.json", None)?; trace!("Trace message"); debug!("Debug message"); info!("Info message"); warn!("Warn message"); error!("Error message"); println!("Welcome to foo, config is:\n{:#?}", cfg); Ok(()) }