Added basic logger
This commit is contained in:
parent
26588b6de7
commit
19d1cc0db0
33
src/logger.rs
Normal file
33
src/logger.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user