diff --git a/src/logger.rs b/src/logger.rs new file mode 100644 index 0000000..5f6c1c6 --- /dev/null +++ b/src/logger.rs @@ -0,0 +1,33 @@ +use std::fs::OpenOptions; +use std::io::prelude::*; +use std::path::Path; + +enum LoggerType { + Local(&'static str), +} + +pub struct Logger { + l_type: LoggerType, +} + +impl Logger { + pub fn new(path: &'static str) -> Logger { + Logger { + l_type: LoggerType::Local(path), + } + } + + pub fn write_log_line(&self, data: String) { + match self.l_type { + LoggerType::Local(path) => { + let mut file = OpenOptions::new() + .write(true) + .append(true) + .create(true) + .open(path) + .unwrap(); + writeln!(file, "{}", data).unwrap(); + } + } + } +}