Mountain/IPC/DevLog/
DebugOnce.rs1#![allow(non_snake_case)]
2
3use std::{
10 collections::HashSet,
11 sync::{Mutex, OnceLock},
12};
13
14use crate::IPC::DevLog::{IsEnabled, WriteToFile};
15
16static DEBUG_ONCE_KEYS:OnceLock<Mutex<HashSet<String>>> = OnceLock::new();
17
18fn DebugOnceKeys() -> &'static Mutex<HashSet<String>> { DEBUG_ONCE_KEYS.get_or_init(|| Mutex::new(HashSet::new())) }
19
20pub fn Fn(Tag:&str, Key:&str, Line:&str) {
21 if let Ok(mut Keys) = DebugOnceKeys().lock() {
22 if !Keys.insert(Key.to_string()) {
23 return;
24 }
25 }
26
27 if IsEnabled::Fn(Tag) || IsEnabled::Fn("all") {
28 let Formatted = format!("[DEV:{}] {}", Tag.to_uppercase(), Line);
29
30 eprintln!("{}", Formatted);
31
32 WriteToFile::Fn(&Formatted);
33 } else {
34 let Formatted = format!("[DEV:{}/once] {}", Tag.to_uppercase(), Line);
35
36 WriteToFile::Fn(&Formatted);
37 }
38}