summary refs log tree commit diff stats
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/semi-structured-logs/src/lib.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/rust/semi-structured-logs/src/lib.rs b/rust/semi-structured-logs/src/lib.rs
index 4f06874..0160b1d 100644
--- a/rust/semi-structured-logs/src/lib.rs
+++ b/rust/semi-structured-logs/src/lib.rs
@@ -1,25 +1,30 @@
+use std::fmt::{Display, Formatter, Result};
+
+#[derive(Debug)]
 pub enum LogLevel {
     Info,
     Warning,
     Error,
 }
 
-pub fn log(level: LogLevel, message: &str) -> String {
-    match level {
-        LogLevel::Info => info(message),
-        LogLevel::Warning => warn(message),
-        LogLevel::Error => error(message),
+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 {
-    format!("[INFO]: {}", message)
+    log(LogLevel::Info, message)
 }
 
 pub fn warn(message: &str) -> String {
-    format!("[WARNING]: {}", message)
+    log(LogLevel::Warning, message)
 }
 
 pub fn error(message: &str) -> String {
-    format!("[ERROR]: {}", message)
+    log(LogLevel::Error, message)
 }