basic logging support

This commit is contained in:
Akshat Deshpande 2023-07-27 14:40:51 -05:00
parent fb7aa45e87
commit 1afca4cd38
7 changed files with 1655 additions and 0 deletions

6
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"./Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": false
}

1624
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -7,3 +7,4 @@ edition = "2021"
[dependencies]
smithay = "0.3.0"
lazy_static = "1.4.0"

16
src/backend/logger.rs Normal file
View file

@ -0,0 +1,16 @@
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();
}

View file

@ -0,0 +1 @@
pub mod logger;

View file

@ -1,3 +1,9 @@
#[macro_use]
extern crate lazy_static;
mod backend;
fn main() {
println!("Hello, world!");
backend::logger::log("Hello, world!");
}

1
waycrab.log Normal file
View file

@ -0,0 +1 @@
Hello, world!