1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
3pub enum Severity {
4 Trace,
6 Debug,
8 Info,
10 Warn,
12 Error,
14 Fatal,
16}
17
18impl Severity {
19 pub const fn as_str(self) -> &'static str {
21 match self {
22 Self::Trace => "TRACE",
23 Self::Debug => "DEBUG",
24 Self::Info => "INFO",
25 Self::Warn => "WARN",
26 Self::Error => "ERROR",
27 Self::Fatal => "FATAL",
28 }
29 }
30}
31
32pub(crate) fn name(value: &str) -> Option<Severity> {
33 let value = value.trim();
34 [
35 (Severity::Trace, &["trace", "trc"][..]),
36 (Severity::Debug, &["debug", "dbg"]),
37 (
38 Severity::Info,
39 &["info", "information", "informational", "notice"],
40 ),
41 (Severity::Warn, &["warn", "warning", "wrn"]),
42 (Severity::Error, &["error", "err", "exception"]),
43 (
44 Severity::Fatal,
45 &["fatal", "critical", "crit", "panic", "emergency"],
46 ),
47 ]
48 .into_iter()
49 .find_map(|(severity, aliases)| {
50 aliases
51 .iter()
52 .any(|alias| value.eq_ignore_ascii_case(alias))
53 .then_some(severity)
54 })
55}
56
57pub(crate) fn pino(value: i64) -> Option<Severity> {
58 match value {
59 10 => Some(Severity::Trace),
60 20 => Some(Severity::Debug),
61 30 => Some(Severity::Info),
62 40 => Some(Severity::Warn),
63 50 => Some(Severity::Error),
64 60 => Some(Severity::Fatal),
65 _ => None,
66 }
67}
68
69pub(crate) fn python(value: i64) -> Option<Severity> {
70 match value {
71 10 => Some(Severity::Debug),
72 20 => Some(Severity::Info),
73 30 => Some(Severity::Warn),
74 40 => Some(Severity::Error),
75 50 => Some(Severity::Fatal),
76 _ => None,
77 }
78}
79
80pub(crate) fn otel(value: i64) -> Option<Severity> {
81 match value {
82 1..=4 => Some(Severity::Trace),
83 5..=8 => Some(Severity::Debug),
84 9..=12 => Some(Severity::Info),
85 13..=16 => Some(Severity::Warn),
86 17..=20 => Some(Severity::Error),
87 21..=24 => Some(Severity::Fatal),
88 _ => None,
89 }
90}