Skip to main content

log_sampled

Function log_sampled 

Source
pub fn log_sampled(counter: &AtomicU64, sample_rate: u64) -> bool
Expand description

Log every Nth occurrence. Returns true on first call and every sample_rate-th call.

Use for per-message errors in hot paths: send failures, validation errors. Always increment metrics separately — this only controls log emission.

§Example

use std::sync::atomic::AtomicU64;
use hyperi_rustlib::logger::log_sampled;

static SEND_ERRORS: AtomicU64 = AtomicU64::new(0);
if log_sampled(&SEND_ERRORS, 1000) {
    // Logs first occurrence, then every 1000th
}