LogSuppressor

Struct LogSuppressor 

Source
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: AtomicUsize

The 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

Source

pub fn new( rate_limiter: RateLimiter<NotKeyed, InMemoryState, MonotonicClock>, ) -> Self

Source

pub fn per_second(per_second: u32) -> Self

Create a LogSuppressor that allows per_second logs per second.

Source

pub fn per_minute(per_minute: u32) -> Self

Create a LogSuppressor that allows per_minute logs per minute.

Source

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§

Source§

impl Default for LogSuppressor

Source§

fn default() -> Self

Default rate limiter allows 1 log per second.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.