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 if IsEnabled::Fn(Tag) || IsEnabled::Fn("all") {
27 let Formatted = format!("[DEV:{}] {}", Tag.to_uppercase(), Line);
28 eprintln!("{}", Formatted);
29 WriteToFile::Fn(&Formatted);
30 } else {
31 let Formatted = format!("[DEV:{}/once] {}", Tag.to_uppercase(), Line);
32 WriteToFile::Fn(&Formatted);
33 }
34}