waycrab/src/backend/logger.rs
2023-07-27 15:00:46 -05:00

23 lines
689 B
Rust

use lazy_static::lazy_static;
lazy_static! {
pub static ref LOG_FILE: Mutex<BufWriter<File>> = {
// here we would add the code to grab the location of the log file from the config file.
// for now, im just using "waycrab.log", which would just place the log file next to the executable. probably.
let writer = BufWriter::new(File::options().append(true).create(true).write(true).open("waycrab.log").unwrap());
writer.into()
};
}
use std::{
fs::File,
io::{BufWriter, Write},
sync::Mutex,
};
pub fn log(entry: &str) {
let mut log = LOG_FILE.lock().unwrap();
log.write_all(entry.as_bytes()).unwrap();
log.flush().unwrap();
}