torrust_index/config/v2/
logging.rs1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use tracing::level_filters::LevelFilter;
5
6#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8pub struct Logging {
9 #[serde(default = "Logging::default_threshold")]
11 pub threshold: Threshold,
12}
13
14impl Default for Logging {
15 fn default() -> Self {
16 Self {
17 threshold: Logging::default_threshold(),
18 }
19 }
20}
21
22impl Logging {
23 fn default_threshold() -> Threshold {
24 Threshold::Info
25 }
26}
27
28#[derive(Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Clone)]
29#[serde(rename_all = "lowercase")]
30pub enum Threshold {
31 Off,
33 Error,
35 Warn,
37 Info,
39 Debug,
41 Trace,
43}
44
45impl Default for Threshold {
46 fn default() -> Self {
47 Self::Info
48 }
49}
50
51impl fmt::Display for Threshold {
52 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53 let display_str = match self {
54 Threshold::Off => "off",
55 Threshold::Error => "error",
56 Threshold::Warn => "warn",
57 Threshold::Info => "info",
58 Threshold::Debug => "debug",
59 Threshold::Trace => "trace",
60 };
61 write!(f, "{display_str}")
62 }
63}
64
65impl From<Threshold> for LevelFilter {
66 fn from(threshold: Threshold) -> Self {
67 match threshold {
68 Threshold::Off => LevelFilter::OFF,
69 Threshold::Error => LevelFilter::ERROR,
70 Threshold::Warn => LevelFilter::WARN,
71 Threshold::Info => LevelFilter::INFO,
72 Threshold::Debug => LevelFilter::DEBUG,
73 Threshold::Trace => LevelFilter::TRACE,
74 }
75 }
76}