radix_engine_interface/types/
level.rs

1use crate::internal_prelude::*;
2#[cfg(feature = "fuzzing")]
3use arbitrary::Arbitrary;
4use core::str::FromStr;
5use sbor::rust::prelude::*;
6
7/// Represents the level of a log message.
8#[cfg_attr(
9    feature = "fuzzing",
10    derive(Arbitrary, serde::Serialize, serde::Deserialize)
11)]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Sbor, Ord, PartialOrd, Default)]
13pub enum Level {
14    Error,
15    Warn,
16    #[default]
17    Info,
18    Debug,
19    Trace,
20}
21
22impl fmt::Display for Level {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            Level::Error => write!(f, "ERROR"),
26            Level::Warn => write!(f, "WARN"),
27            Level::Info => write!(f, "INFO"),
28            Level::Debug => write!(f, "DEBUG"),
29            Level::Trace => write!(f, "TRACE"),
30        }
31    }
32}
33
34impl FromStr for Level {
35    type Err = String;
36
37    fn from_str(s: &str) -> Result<Self, Self::Err> {
38        match s {
39            "ERROR" => Ok(Self::Error),
40            "WARN" => Ok(Self::Warn),
41            "INFO" => Ok(Self::Info),
42            "DEBUG" => Ok(Self::Debug),
43            "TRACE" => Ok(Self::Trace),
44            _ => Err(format!("Invalid level: {}", s)),
45        }
46    }
47}