rework (error) logging

This commit is contained in:
2025-05-16 10:03:48 +01:00
parent 9dbfbc4419
commit 10e69eaac3
6 changed files with 78 additions and 18 deletions
+20
View File
@@ -0,0 +1,20 @@
use crate::util::consts::path;
use std::{fs::File, io::Write};
use strum::Display;
#[derive(Display)]
pub enum LogLevel {
Error,
Panic,
}
pub fn log(level: LogLevel, message: String) {
let mut file = File::options()
.create(true)
.append(true)
.open(path::APP_LOG.as_path())
.unwrap();
let timestamp = chrono::Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, false);
let message = format!("[{timestamp}] [{level}]\n{message}\n\n");
file.write_all(message.as_bytes()).unwrap();
}