rivet-logger 0.1.0

Rivet framework crates and adapters.
Documentation
use std::error::Error;
use std::fmt::{Display, Formatter};

use super::BoxError;

#[derive(Debug)]
pub enum LoggerError {
    EmptyHandlerStack,
    EmptyProcessorStack,
    InvalidLevelValue(String),
    InvalidProcessorConfig(String),
    Unhandled(BoxError),
}

impl Display for LoggerError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::EmptyHandlerStack => write!(f, "handler stack is empty"),
            Self::EmptyProcessorStack => write!(f, "processor stack is empty"),
            Self::InvalidLevelValue(level) => write!(
                f,
                "level \"{level}\" is not defined, use one of: DEBUG, INFO, NOTICE, WARNING, ERROR, CRITICAL, ALERT, EMERGENCY"
            ),
            Self::InvalidProcessorConfig(message) => write!(f, "{message}"),
            Self::Unhandled(err) => write!(f, "{err}"),
        }
    }
}

impl Error for LoggerError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        match self {
            Self::Unhandled(err) => Some(err.as_ref()),
            _ => None,
        }
    }
}