Skip to content

Commit 0cba31f

Browse files
henghongleejkczyz
authored andcommitted
Pass Record by value to Logger
Instead of passing a reference to a Record, pass the Logger an owned Record so that it can be decorated with semantic context.
1 parent 74bc9e2 commit 0cba31f

File tree

11 files changed

+13
-13
lines changed

11 files changed

+13
-13
lines changed

fuzz/src/full_stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ mod tests {
728728
pub lines: Mutex<HashMap<(String, String), usize>>,
729729
}
730730
impl Logger for TrackingLogger {
731-
fn log(&self, record: &Record) {
731+
fn log(&self, record: Record) {
732732
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
733733
println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
734734
}

fuzz/src/onion_message.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ mod tests {
218218
pub lines: Mutex<HashMap<(String, String), usize>>,
219219
}
220220
impl Logger for TrackingLogger {
221-
fn log(&self, record: &Record) {
221+
fn log(&self, record: Record) {
222222
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
223223
println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
224224
}

fuzz/src/utils/test_logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, Out: Output> Write for LockedWriteAdapter<'a, Out> {
5656
}
5757

5858
impl<Out: Output> Logger for TestLogger<Out> {
59-
fn log(&self, record: &Record) {
59+
fn log(&self, record: Record) {
6060
write!(LockedWriteAdapter(&self.out),
6161
"{:<5} {} [{} : {}] {}\n", record.level.to_string(), self.id, record.module_path, record.line, record.args)
6262
.unwrap();

lightning-net-tokio/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ mod tests {
571571

572572
pub struct TestLogger();
573573
impl lightning::util::logger::Logger for TestLogger {
574-
fn log(&self, record: &lightning::util::logger::Record) {
574+
fn log(&self, record: lightning::util::logger::Record) {
575575
println!("{:<5} [{} : {}, {}] {}", record.level.to_string(), record.module_path, record.file, record.line, record.args);
576576
}
577577
}

lightning-rapid-gossip-sync/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
//! # use lightning::util::logger::{Logger, Record};
5050
//! # struct FakeLogger {}
5151
//! # impl Logger for FakeLogger {
52-
//! # fn log(&self, record: &Record) { }
52+
//! # fn log(&self, record: Record) { }
5353
//! # }
5454
//! # let logger = FakeLogger {};
5555
//!

lightning/src/onion_message/messenger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ use crate::prelude::*;
7171
/// # use std::sync::Arc;
7272
/// # struct FakeLogger;
7373
/// # impl Logger for FakeLogger {
74-
/// # fn log(&self, record: &Record) { unimplemented!() }
74+
/// # fn log(&self, record: Record) { unimplemented!() }
7575
/// # }
7676
/// # struct FakeMessageRouter {}
7777
/// # impl MessageRouter for FakeMessageRouter {

lightning/src/routing/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8116,7 +8116,7 @@ pub mod benches {
81168116

81178117
struct DummyLogger {}
81188118
impl Logger for DummyLogger {
8119-
fn log(&self, _record: &Record) {}
8119+
fn log(&self, _record: Record) {}
81208120
}
81218121

81228122
pub fn generate_routes_with_zero_penalty_scorer(bench: &mut Criterion) {

lightning/src/routing/scoring.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! #
2727
//! # struct FakeLogger {};
2828
//! # impl Logger for FakeLogger {
29-
//! # fn log(&self, record: &Record) { unimplemented!() }
29+
//! # fn log(&self, record: Record) { unimplemented!() }
3030
//! # }
3131
//! # fn find_scored_route(payer: PublicKey, route_params: RouteParameters, network_graph: NetworkGraph<&FakeLogger>) {
3232
//! # let logger = FakeLogger {};

lightning/src/util/logger.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ impl<'a> Record<'a> {
135135
}
136136
}
137137

138-
/// A trait encapsulating the operations required of a logger
138+
/// A trait encapsulating the operations required of a logger.
139139
pub trait Logger {
140-
/// Logs the `Record`
141-
fn log(&self, record: &Record);
140+
/// Logs the [`Record`].
141+
fn log(&self, record: Record);
142142
}
143143

144144
/// Wrapper for logging a [`PublicKey`] in hex format.

lightning/src/util/macro_logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ macro_rules! log_spendable {
159159
#[macro_export]
160160
macro_rules! log_internal {
161161
($logger: expr, $lvl:expr, $($arg:tt)+) => (
162-
$logger.log(&$crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()))
162+
$logger.log($crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()))
163163
);
164164
}
165165

lightning/src/util/test_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl TestLogger {
979979
}
980980

981981
impl Logger for TestLogger {
982-
fn log(&self, record: &Record) {
982+
fn log(&self, record: Record) {
983983
*self.lines.lock().unwrap().entry((record.module_path.to_string(), format!("{}", record.args))).or_insert(0) += 1;
984984
if record.level >= self.level {
985985
#[cfg(all(not(ldk_bench), feature = "std"))] {

0 commit comments

Comments
 (0)