pub struct LogSuppressor {
pub(crate) suppressed_count: AtomicUsize,
pub(crate) rate_limiter: RateLimiter<NotKeyed, InMemoryState, MonotonicClock>,
}Expand description
LogSuppressor is a helper to suppress log spamming.
Fields§
§suppressed_count: AtomicUsizeThe number of times the log has been suppressed. Will be returned and cleared when the rate limiter allows next log to be printed.
rate_limiter: RateLimiter<NotKeyed, InMemoryState, MonotonicClock>Inner rate limiter.
Implementations§
Source§impl LogSuppressor
impl LogSuppressor
pub fn new( rate_limiter: RateLimiter<NotKeyed, InMemoryState, MonotonicClock>, ) -> Self
Sourcepub fn per_second(per_second: u32) -> Self
pub fn per_second(per_second: u32) -> Self
Create a LogSuppressor that allows per_second logs per second.
Sourcepub fn per_minute(per_minute: u32) -> Self
pub fn per_minute(per_minute: u32) -> Self
Create a LogSuppressor that allows per_minute logs per minute.
Sourcepub fn check(&self) -> Result<Option<NonZeroUsize>, LogSuppressed>
pub fn check(&self) -> Result<Option<NonZeroUsize>, LogSuppressed>
Check if the log should be suppressed.
If the log should be suppressed, return Err(LogSuppressed).
Otherwise, return Ok(Some(..)) with count of suppressed messages since last check,
or Ok(None) if there’s none.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for LogSuppressor
impl RefUnwindSafe for LogSuppressor
impl Send for LogSuppressor
impl Sync for LogSuppressor
impl Unpin for LogSuppressor
impl UnwindSafe for LogSuppressor
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