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