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