summary refs log blame commit diff stats
path: root/rust/semi-structured-logs/src/lib.rs
blob: 0160b1de88e442defbcdd71cd7bbf56cff46caec (plain) (tree)
1
2
3
4
5
6
7
8
9


                                           





                   


                                                


     



                                                                  
                                      
                                


                                      
                                   


                                       
                                 
 
use std::fmt::{Display, Formatter, Result};

#[derive(Debug)]
pub enum LogLevel {
    Info,
    Warning,
    Error,
}

impl Display for LogLevel {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(f, "{:?}", self)
    }
}

pub fn log(level: LogLevel, message: &str) -> String {
    format!("[{}]: {}", level.to_string().to_uppercase(), message)
}

pub fn info(message: &str) -> String {
    log(LogLevel::Info, message)
}

pub fn warn(message: &str) -> String {
    log(LogLevel::Warning, message)
}

pub fn error(message: &str) -> String {
    log(LogLevel::Error, message)
}