1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
    Appellation: loggers <module>
    Contributors: FL03 <jo3mccain@icloud.com> (https://github.com)
    Description:
        ... Summary ...
*/
use super::logger_from_env;
use serde::{Deserialize, Serialize};
use tracing_subscriber;

#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Logger {
    pub level: String,
}

impl Logger {
    pub fn new(level: String) -> Self {
        Self { level }
    }

    pub fn from<T: std::string::ToString>(level: T) -> Self {
        Self::new(level.to_string())
    }

    pub fn setup(&self) {
        logger_from_env(Some(self.level.clone().as_str()))
    }
}

impl std::convert::From<&str> for Logger {
    fn from(level: &str) -> Self {
        Self::new(level.to_string())
    }
}