slog_html/
color_palette.rs

1use slog::Level;
2
3/// Hexadecimal color codes
4pub struct ColorPalette {
5    /// Color for critical messages
6    pub critical: &'static str,
7
8    /// Color for error messages
9    pub error: &'static str,
10
11    /// Color for warning messages
12    pub warning: &'static str,
13
14    /// Color for info messages
15    pub info: &'static str,
16
17    /// Color for debug messages
18    pub debug: &'static str,
19
20    /// Color for trace messages
21    pub trace: &'static str,
22}
23
24impl ColorPalette {
25    /// Returns the corresponding color for an slog level
26    pub fn level_to_color(&self, level: Level) -> &'static str {
27        use slog::Level::*;
28        match level {
29            Critical => self.critical,
30            Error => self.error,
31            Warning => self.warning,
32            Info => self.info,
33            Debug => self.debug,
34            Trace => self.trace,
35        }
36    }
37}
38
39impl Default for ColorPalette {
40    /// ```text
41    /// critical: "ff0000"
42    /// error: "ff5500"
43    /// warning: "ffaa00"
44    /// info: "55aa00"
45    /// debug: "55557f"
46    /// trace: "aaaa7f"
47    /// ```
48    fn default() -> Self {
49        ColorPalette {
50            critical: "ff0000",
51            error: "ff5500",
52            warning: "ffaa00",
53            info: "55aa00",
54            debug: "55557f",
55            trace: "aaaa7f",
56        }
57    }
58}