use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; use std::sync::OnceLock; use std::time::{SystemTime, UNIX_EPOCH}; fn log_path() -> &'static PathBuf { static PATH: OnceLock = OnceLock::new(); PATH.get_or_init(|| crate::paths::native_log(std::process::id())) } pub fn log(message: &str) { let secs = SystemTime::now().duration_since(UNIX_EPOCH).map(|d| d.as_secs()).unwrap_or(0); if let Some(parent) = log_path().parent() { let _ = std::fs::create_dir_all(parent); } if let Ok(mut file) = OpenOptions::new().create(true).append(true).open(log_path()) { let _ = writeln!(file, "[{secs}] {message}"); } } #[macro_export] macro_rules! log { ($($arg:tt)*) => { $crate::log::log(&format!($($arg)*)) }; }