summary refs log tree commit diff stats
path: root/rust/semi-structured-logs/src/lib.rs
blob: 0160b1de88e442defbcdd71cd7bbf56cff46caec (plain) (blame)
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
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)
}