waycrab/src/backend/logger.rs

16 lines
642 B
Rust

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::{io::{BufWriter, Write}, fs::File, sync::Mutex};
pub fn log(entry: &str) {
let mut log = LOG_FILE.lock().unwrap();
log.write_all(entry.as_bytes()).unwrap();
log.flush().unwrap();
}