1use std::{
2 fs::{File, OpenOptions},
3 sync::Mutex,
4};
5
6use once_cell::sync::Lazy;
7
8static _LOG_FILE: Lazy<Mutex<File>> = Lazy::new(|| {
9 Mutex::new(
10 OpenOptions::new()
11 .create(true)
12 .truncate(true)
13 .read(true)
14 .write(true)
15 .open("debug.log")
16 .unwrap(),
17 )
18});
19
20#[macro_export]
21macro_rules! trace {
22 ($($arg:tt)*) => {
23 $crate::debug::trace_log(format!($($arg)*))
24 };
25}
26
27pub fn trace_log(_str: impl AsRef<str>) {
28 #[cfg(feature = "debug")]
29 {
30 use std::io::Write;
31 let mut file = _LOG_FILE.lock().unwrap();
32 writeln!(file, "{}", _str.as_ref()).unwrap();
33 }
34}
35
36#[allow(unused_imports)]
37pub(crate) use trace;