Skip to content

Commit 62de1c6

Browse files
committed
No longer require Sink::log to call should_log to filter records
1 parent 7f2ca54 commit 62de1c6

File tree

10 files changed

+11
-39
lines changed

10 files changed

+11
-39
lines changed

spdlog/benches/spdlog-rs/pattern.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ impl<F: Formatter> Sink for BenchSink<F> {
5050
unimplemented!()
5151
}
5252

53-
fn level_filter(&self) -> spdlog::LevelFilter {
54-
unimplemented!()
53+
fn level_filter(&self) -> LevelFilter {
54+
LevelFilter::All
5555
}
5656

57-
fn set_level_filter(&self, _level_filter: spdlog::LevelFilter) {
57+
fn set_level_filter(&self, _level_filter: LevelFilter) {
5858
unimplemented!()
5959
}
6060

spdlog/src/logger.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,10 @@ impl Logger {
389389

390390
fn sink_record(&self, record: &Record) {
391391
self.sinks.iter().for_each(|sink| {
392-
if let Err(err) = sink.log(record) {
393-
self.handle_error(err);
392+
if sink.should_log(record.level()) {
393+
if let Err(err) = sink.log(record) {
394+
self.handle_error(err);
395+
}
394396
}
395397
});
396398

spdlog/src/sink/async_sink/async_pool_sink.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,10 @@ impl AsyncPoolSink {
6868

6969
impl Sink for AsyncPoolSink {
7070
fn log(&self, record: &Record) -> Result<()> {
71-
if self.should_log(record.level()) {
72-
self.assign_task(Task::Log {
73-
backend: self.clone_backend(),
74-
record: record.to_owned(),
75-
})?;
76-
}
77-
Ok(())
71+
self.assign_task(Task::Log {
72+
backend: self.clone_backend(),
73+
record: record.to_owned(),
74+
})
7875
}
7976

8077
fn flush(&self) -> Result<()> {

spdlog/src/sink/file_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ impl FileSink {
6363

6464
impl Sink for FileSink {
6565
fn log(&self, record: &Record) -> Result<()> {
66-
if !self.should_log(record.level()) {
67-
return Ok(());
68-
}
69-
7066
let mut string_buf = StringBuf::new();
7167
self.common_impl
7268
.formatter

spdlog/src/sink/journald_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ impl JournaldSink {
105105

106106
impl Sink for JournaldSink {
107107
fn log(&self, record: &Record) -> Result<()> {
108-
if !self.should_log(record.level()) {
109-
return Ok(());
110-
}
111-
112108
let mut string_buf = StringBuf::new();
113109
self.common_impl
114110
.formatter

spdlog/src/sink/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ pub trait Sink: Sync + Send {
8787
}
8888

8989
/// Logs a record.
90-
///
91-
/// Implementors should always call [`Sink::should_log`] internally to
92-
/// filter records.
9390
fn log(&self, record: &Record) -> Result<()>;
9491

9592
/// Flushes any buffered records.

spdlog/src/sink/rotating_file_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,6 @@ impl RotatingFileSink {
286286

287287
impl Sink for RotatingFileSink {
288288
fn log(&self, record: &Record) -> Result<()> {
289-
if !self.should_log(record.level()) {
290-
return Ok(());
291-
}
292-
293289
let mut string_buf = StringBuf::new();
294290
self.common_impl
295291
.formatter

spdlog/src/sink/std_stream_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,6 @@ impl StdStreamSink {
143143

144144
impl Sink for StdStreamSink {
145145
fn log(&self, record: &Record) -> Result<()> {
146-
if !self.should_log(record.level()) {
147-
return Ok(());
148-
}
149-
150146
let mut string_buf = StringBuf::new();
151147
let extra_info = self
152148
.common_impl

spdlog/src/sink/win_debug_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ impl Sink for WinDebugSink {
3636
#[cfg(windows)] // https://github.com/rust-lang/rust/issues/97976
3737
use std::os::windows::ffi::OsStrExt;
3838

39-
if !self.should_log(record.level()) {
40-
return Ok(());
41-
}
42-
4339
let mut string_buf = StringBuf::new();
4440
self.common_impl
4541
.formatter

spdlog/src/sink/write_sink.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ where
8585
W: Write + Send,
8686
{
8787
fn log(&self, record: &Record) -> Result<()> {
88-
if !self.should_log(record.level()) {
89-
return Ok(());
90-
}
91-
9288
let mut string_buf = StringBuf::new();
9389
self.common_impl
9490
.formatter

0 commit comments

Comments
 (0)