censer 0.1.0

Beautiful, structured logging for the terminal âš’ī¸
Documentation
//! Log levels.

use glyphs::Color;

/// Log level.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Level {
    /// Debug level - verbose debugging info.
    Debug,
    /// Info level - general information.
    Info,
    /// Warn level - warnings.
    Warn,
    /// Error level - errors.
    Error,
    /// Fatal level - critical errors.
    Fatal,
}

impl Level {
    /// Get the display name for this level.
    #[must_use]
    pub const fn name(&self) -> &'static str {
        match self {
            Level::Debug => "DEBUG",
            Level::Info => "INFO",
            Level::Warn => "WARN",
            Level::Error => "ERROR",
            Level::Fatal => "FATAL",
        }
    }

    /// Get the short name (3 chars).
    #[must_use]
    pub const fn short_name(&self) -> &'static str {
        match self {
            Level::Debug => "DBG",
            Level::Info => "INF",
            Level::Warn => "WRN",
            Level::Error => "ERR",
            Level::Fatal => "FTL",
        }
    }

    /// Get the icon for this level.
    #[must_use]
    pub const fn icon(&self) -> &'static str {
        match self {
            Level::Debug => "🔍",
            Level::Info => "â„šī¸",
            Level::Warn => "âš ī¸",
            Level::Error => "❌",
            Level::Fatal => "💀",
        }
    }

    /// Get the default color for this level.
    #[must_use]
    pub fn color(&self) -> Color {
        match self {
            Level::Debug => Color::from_hex("#71717A"), // Gray
            Level::Info => Color::from_hex("#3B82F6"),  // Blue
            Level::Warn => Color::from_hex("#F59E0B"),  // Amber
            Level::Error => Color::from_hex("#EF4444"), // Red
            Level::Fatal => Color::from_hex("#DC2626"), // Dark red
        }
    }
}

impl std::fmt::Display for Level {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.name())
    }
}