lunar-lib 0.10.0

Common utilities for lunar applications
Documentation
#[cfg(feature = "cli-logger")]
mod cli_logger;
#[cfg(feature = "cli-logger")]
pub use cli_logger::*;

pub use log::*;

#[derive(Debug, thiserror::Error)]
pub enum LogFilterParseError {
    #[error("Invalid log level: {0}")]
    InvalidInput(String),
}

pub fn parse_level_filter(s: &str) -> Result<log::LevelFilter, LogFilterParseError> {
    match s.to_ascii_lowercase().as_str() {
        "off" | "quiet" => Ok(log::LevelFilter::Off),
        "error" => Ok(log::LevelFilter::Error),
        "warn" => Ok(log::LevelFilter::Warn),
        "info" => Ok(log::LevelFilter::Info),
        "debug" => Ok(log::LevelFilter::Debug),
        "trace" => Ok(log::LevelFilter::Trace),
        _ => Err(LogFilterParseError::InvalidInput(s.to_owned())),
    }
}