Skip to content

Commit 4629ee2

Browse files
committed
Implement Display for Record
As a preparatory step for unifying test log output.
1 parent cbbda61 commit 4629ee2

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7336,7 +7336,7 @@ pub fn test_concurrent_monitor_claim() {
73367336

73377337
// Copy ChainMonitor to simulate watchtower Alice and update block height her ChannelMonitor timeout HTLC onchain
73387338
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
7339-
let logger = test_utils::TestLogger::with_id(format!("node {}", "Alice"));
7339+
let logger = test_utils::TestLogger::with_id("alice".to_string());
73407340
let persister = test_utils::TestPersister::new();
73417341
let alice_broadcaster = test_utils::TestBroadcaster::with_blocks(Arc::new(Mutex::new(
73427342
nodes[0].blocks.lock().unwrap().clone(),
@@ -7387,7 +7387,7 @@ pub fn test_concurrent_monitor_claim() {
73877387

73887388
// Copy ChainMonitor to simulate watchtower Bob and make it receive a commitment update first.
73897389
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
7390-
let logger = test_utils::TestLogger::with_id(format!("node {}", "Bob"));
7390+
let logger = test_utils::TestLogger::with_id("bob".to_string());
73917391
let persister = test_utils::TestPersister::new();
73927392
let bob_broadcaster =
73937393
test_utils::TestBroadcaster::with_blocks(Arc::clone(&alice_broadcaster.blocks));

lightning/src/util/logger.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use bitcoin::secp256k1::PublicKey;
1717

1818
use core::cmp;
1919
use core::fmt;
20+
use core::fmt::Display;
2021
use core::ops::Deref;
2122

2223
use crate::ln::types::ChannelId;
@@ -152,6 +153,13 @@ impl<$($args)?> Record<$($args)?> {
152153
}
153154
}
154155
}
156+
157+
impl<$($args)?> Display for Record<$($args)?> {
158+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159+
let context = format!("{} [{}:{}]", self.level, self.module_path, self.line);
160+
write!(f, "{:<48} {}", context, self.args)
161+
}
162+
}
155163
} }
156164
#[cfg(not(c_bindings))]
157165
impl_record!('a, );

lightning/src/util/test_utils.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,9 +1698,7 @@ impl TestLogger {
16981698

16991699
impl Logger for TestLogger {
17001700
fn log(&self, record: Record) {
1701-
let context =
1702-
format!("{} {} [{}:{}]", self.id, record.level, record.module_path, record.line);
1703-
let s = format!("{:<55} {}", context, record.args);
1701+
let s = format!("{:<6} {}", self.id, record);
17041702
#[cfg(ldk_bench)]
17051703
{
17061704
// When benchmarking, we don't actually want to print logs, but we do want to format

0 commit comments

Comments
 (0)