Skip to content

Commit abb98ae

Browse files
committed
Skip log formatting entirely for DevNull output
Even though DevNull discards the bytes, the formatting work (SubstringFormatter, fmt::write, from_utf8) was still being done on every log call. Short-circuit in TestLogger::log via a TypeId check, which monomorphization resolves at compile time. AI tools were used in preparing this commit.
1 parent eb57001 commit abb98ae

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fuzz/src/utils/test_logger.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// licenses.
99

1010
use lightning::util::logger::{Logger, Record};
11+
use std::any::TypeId;
1112
use std::io::Write;
1213
use std::sync::{Arc, Mutex};
1314

@@ -66,6 +67,9 @@ impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {
6667

6768
impl<Out: Output> Logger for TestLogger<Out> {
6869
fn log(&self, record: Record) {
70+
if TypeId::of::<Out>() == TypeId::of::<DevNull>() {
71+
return;
72+
}
6973
writeln!(LockedWriteAdapter(&self.out), "{:<6} {}", self.id, record).unwrap();
7074
}
7175
}

0 commit comments

Comments
 (0)