Added basic logger

This commit is contained in:
Benjamyn Love 2024-04-23 09:55:08 +10:00
parent 26588b6de7
commit 19d1cc0db0

33
src/logger.rs Normal file
View File

@ -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();
}
}
}
}