Skip to main content

tui_kit/
log.rs

1use std::time::Instant;
2
3use ratatui::style::Color;
4
5/// Severity level for a log entry.
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub enum LogLevel {
8    Debug,
9    Info,
10    Warning,
11    Error,
12}
13
14impl LogLevel {
15    /// The display color associated with this level.
16    pub fn color(self) -> Color {
17        match self {
18            LogLevel::Debug => Color::DarkGray,
19            LogLevel::Info => Color::Gray,
20            LogLevel::Warning => Color::Yellow,
21            LogLevel::Error => Color::Red,
22        }
23    }
24}
25
26/// A single timestamped log entry with a severity level.
27#[derive(Debug, Clone)]
28pub struct LogEntry {
29    pub timestamp: String,
30    pub level: LogLevel,
31    pub message: String,
32    /// Wall-clock time of creation, used to evict entries older than 24 h.
33    pub created_at: Instant,
34}