radix_engine_interface/types/
level.rs

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