use log::LevelFilter; use serde::{Deserialize, Serialize}; #[derive(Serialize, Debug, Deserialize)] pub enum LogLevel { /// A level lower than all log levels. Off, /// Corresponds to the `Error` log level. Error, /// Corresponds to the `Warn` log level. Warn, /// Corresponds to the `Info` log level. Info, /// Corresponds to the `Debug` log level. Debug, /// Corresponds to the `Trace` log level. Trace, } #[derive(Serialize, Debug, Deserialize)] pub struct BootConfig { pub logging_level: LogLevel, pub run_tests: bool, pub run_demos: bool, pub run_shader_tests: bool, } impl BootConfig { pub fn new() -> Self { let data = include_str!("../assets/kernel_config.json"); // Parse the string of data into a Person object. This is exactly the // same function as the one that produced serde_json::Value above, but // now we are asking it for a Person as output. let p: BootConfig = serde_json::from_str(data).unwrap(); info!("{:?}", p); p } pub fn log_level(&self) -> LevelFilter { use LevelFilter::*; match self.logging_level { LogLevel::Off => Off, LogLevel::Error => Error, LogLevel::Warn => Warn, LogLevel::Info => Info, LogLevel::Debug => Debug, LogLevel::Trace => Trace, } } }