1use std::fs::{File, OpenOptions};
4use std::io::Write;
5use std::path::Path;
6use std::sync::Mutex;
7
8static LOG: Mutex<Option<File>> = Mutex::new(None);
9
10pub fn open(path: &Path) -> std::io::Result<()> {
12 let f = OpenOptions::new().append(true).create(true).open(path)?;
13 if let Ok(mut g) = LOG.lock() {
14 *g = Some(f);
15 }
16 Ok(())
17}
18
19pub fn log(msg: &str) {
22 if let Ok(mut g) = LOG.lock() {
23 if let Some(f) = g.as_mut() {
24 let ts = chrono::Local::now().format("%Y-%m-%dT%H:%M:%S");
25 let _ = writeln!(f, "[{ts}] {msg}");
26 let _ = f.flush();
27 }
28 }
29}