pub struct LogSampler { /* private fields */ }Expand description
A 1-in-N gate for high-volume log lines. Construct once per high-volume
site (or share via Arc) and call LogSampler::should_emit at the log
point:
use brainos_observe::LogSampler;
let sampler = LogSampler::one_in(100);
for i in 0..250 {
if sampler.should_emit() {
// ~1 in 100 of these run; the other 99 are skipped.
let _ = i;
}
}Implementations§
Source§impl LogSampler
impl LogSampler
Sourcepub fn unsampled() -> Self
pub fn unsampled() -> Self
A sampler that emits on every call — the explicit “sampling off” form.
Sourcepub fn should_emit(&self) -> bool
pub fn should_emit(&self) -> bool
Whether this call should emit its log line. Returns true on the
1st call and every one_in_n-th call thereafter, so a freshly built
sampler always logs its first occurrence (you never lose the first
instance of a newly-hot site).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LogSampler
impl RefUnwindSafe for LogSampler
impl Send for LogSampler
impl Sync for LogSampler
impl Unpin for LogSampler
impl UnsafeUnpin for LogSampler
impl UnwindSafe for LogSampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more