pub struct DedupSink { /* private fields */ }
Expand description
A combined sink, skip consecutive repeated records.
More than 2 consecutive repeated records, the records after the first one
will be replaced with a single record "(skipped {count} duplicates)"
.
The skip will stop if the incoming record compares to the last skipped records:
- content changed, or
- logging level changed, or
- interval exceeded the skip duration
§Example
use std::time::Duration;
use spdlog::{prelude::*, sink::DedupSink};
let sink = Arc::new(
DedupSink::builder()
.sink(underlying_sink)
.skip_duration(Duration::from_secs(1))
.build()?
);
// ... Add the `sink` to a logger
info!(logger: doctest, "I wish I was a cat");
info!(logger: doctest, "I wish I was a cat");
info!(logger: doctest, "I wish I was a cat");
// The skip will stop since the content changed.
info!(logger: doctest, "No school");
info!(logger: doctest, "No works");
info!(logger: doctest, "Just meow meow");
/* Output of `underlying_sink` */
r#"I wish I was a cat
(skipped 2 duplicates)
No school
No works
Just meow meow
"#
Implementations§
Source§impl DedupSink
impl DedupSink
Sourcepub fn builder() -> DedupSinkBuilder<()>
pub fn builder() -> DedupSinkBuilder<()>
Gets a builder of DedupSink
with default parameters:
Parameter | Default Value |
---|---|
level_filter | All |
formatter | FullFormatter |
error_handler | default error handler |
sinks | [] |
skip_duration | must be specified |
Trait Implementations§
Source§impl Sink for DedupSink
impl Sink for DedupSink
Source§fn level_filter(&self) -> LevelFilter
fn level_filter(&self) -> LevelFilter
Gets the log level filter.
Source§fn set_level_filter(&self, level_filter: LevelFilter)
fn set_level_filter(&self, level_filter: LevelFilter)
Sets the log level filter.
Source§fn set_formatter(&self, formatter: Box<dyn Formatter>)
fn set_formatter(&self, formatter: Box<dyn Formatter>)
Sets the formatter.
Source§fn set_error_handler(&self, handler: Option<ErrorHandler>)
fn set_error_handler(&self, handler: Option<ErrorHandler>)
Sets a error handler. Read more
Source§fn should_log(&self, level: Level) -> bool
fn should_log(&self, level: Level) -> bool
Determines if a log message with the specified level would be logged.
Auto Trait Implementations§
impl !Freeze for DedupSink
impl !RefUnwindSafe for DedupSink
impl Send for DedupSink
impl Sync for DedupSink
impl Unpin for DedupSink
impl !UnwindSafe for DedupSink
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