ferroui_splat/logging/log_level.rs
1//! `LogLevel`.
2
3use std::fmt;
4
5/// The level of a message (`LogLevel`), from the most verbose to the most severe. A logger writes
6/// the messages of its level and above.
7#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub enum LogLevel {
9 /// Messages for debugging.
10 Debug = 1,
11 /// Information.
12 Info,
13 /// Warnings.
14 Warn,
15 /// Errors.
16 Error,
17 /// Errors the application cannot recover from.
18 Fatal,
19}
20
21/// The name of the level, as `Enum.ToString` writes it (`Debug`, `Info`, ...).
22impl fmt::Display for LogLevel {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 f.write_str(match self {
25 Self::Debug => "Debug",
26 Self::Info => "Info",
27 Self::Warn => "Warn",
28 Self::Error => "Error",
29 Self::Fatal => "Fatal",
30 })
31 }
32}
33
34impl Default for LogLevel {
35 /// The level of a logger whose level was not set: upstream's `default(LogLevel)` is 0, below
36 /// `Debug`, so such a logger writes everything; `Debug` does the same here.
37 // Deviation (DEVIATIONS.md, Splat): the enum has no value 0; a logger that was not given a
38 // level starts at `Debug`, which writes the same messages.
39 fn default() -> Self {
40 Self::Debug
41 }
42}