mistralrs_quant/utils/
log.rs

1use std::{
2    hash::{DefaultHasher, Hash, Hasher},
3    sync::Mutex,
4};
5
6use once_cell::sync::Lazy;
7use tracing::{info, warn};
8
9static CACHED_INFO: Lazy<Mutex<Vec<u64>>> = Lazy::new(|| Mutex::new(Vec::new()));
10static CACHED_WARN: Lazy<Mutex<Vec<u64>>> = Lazy::new(|| Mutex::new(Vec::new()));
11
12pub fn once_log_info<M: AsRef<str>>(msg: M) {
13    let msg = msg.as_ref();
14    let mut hasher = DefaultHasher::new();
15    msg.hash(&mut hasher);
16    let hash = hasher.finish();
17
18    let mut log = CACHED_INFO.lock().expect("Poisoned Lock");
19    if !log.contains(&hash) {
20        info!("{msg}");
21        log.push(hasher.finish());
22    } else {
23        log.push(hasher.finish());
24    }
25}
26
27pub fn once_log_warn<M: AsRef<str>>(msg: M) {
28    let msg = msg.as_ref();
29    let mut hasher = DefaultHasher::new();
30    msg.hash(&mut hasher);
31    let hash = hasher.finish();
32
33    let mut log = CACHED_WARN.lock().expect("Poisoned Lock");
34    if !log.contains(&hash) {
35        warn!("{msg}");
36        log.push(hasher.finish());
37    } else {
38        log.push(hasher.finish());
39    }
40}