What changed, and why it matters
This commit adds a standard way to print log records and updates test code to use it. It is a code cleanup/refactoring change with no security relevance.
No security action needed. Treat as normal refactoring/test-output cleanup.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit implements the Display trait for the Record logging struct in lightning/src/util/logger.rs, formatting log output as a fixed-width string containing the log level, module path, line number, and message arguments. It then updates TestLogger in lightning/src/util/test_utils.rs to delegate formatting to Record::Display instead of building the string inline. Two test cases in functional_tests.rs are adjusted to use simpler logger IDs (‘alice’/’bob’ instead of ‘node Alice’/’node Bob’). There are no functional, cryptographic, or security behavior changes.
Changed components
lightning/src/util/logger.rslightning/src/util/test_utils.rslightning/src/ln/functional_tests.rsInspect captured patch +11 / −5
diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs
index 8bab54f..679d28d 100644
--- a/lightning/src/ln/functional_tests.rs
+++ b/lightning/src/ln/functional_tests.rs
@@ -7350,7 +7350,7 @@ pub fn test_concurrent_monitor_claim() {
// Copy ChainMonitor to simulate watchtower Alice and update block height her ChannelMonitor timeout HTLC onchain
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
- let logger = test_utils::TestLogger::with_id(format!("node {}", "Alice"));
+ let logger = test_utils::TestLogger::with_id("alice".to_string());
let persister = test_utils::TestPersister::new();
let alice_broadcaster = test_utils::TestBroadcaster::with_blocks(Arc::new(Mutex::new(
nodes[0].blocks.lock().unwrap().clone(),
@@ -7401,7 +7401,7 @@ pub fn test_concurrent_monitor_claim() {
// Copy ChainMonitor to simulate watchtower Bob and make it receive a commitment update first.
let chain_source = test_utils::TestChainSource::new(Network::Testnet);
- let logger = test_utils::TestLogger::with_id(format!("node {}", "Bob"));
+ let logger = test_utils::TestLogger::with_id("bob".to_string());
let persister = test_utils::TestPersister::new();
let bob_broadcaster =
test_utils::TestBroadcaster::with_blocks(Arc::clone(&alice_broadcaster.blocks));
diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs
index 283d315..253e8bd 100644
--- a/lightning/src/util/logger.rs
+++ b/lightning/src/util/logger.rs
@@ -17,6 +17,7 @@ use bitcoin::secp256k1::PublicKey;
use core::cmp;
use core::fmt;
+use core::fmt::Display;
use core::ops::Deref;
use crate::ln::types::ChannelId;
@@ -152,6 +153,13 @@ impl<$($args)?> Record<$($args)?> {
}
}
}
+
+impl<$($args)?> Display for Record<$($args)?> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let context = format!("{} [{}:{}]", self.level, self.module_path, self.line);
+ write!(f, "{:<48} {}", context, self.args)
+ }
+}
} }
#[cfg(not(c_bindings))]
impl_record!('a, );
diff --git a/lightning/src/util/test_utils.rs b/lightning/src/util/test_utils.rs
index bfa1efb..5f408a9 100644
--- a/lightning/src/util/test_utils.rs
+++ b/lightning/src/util/test_utils.rs
@@ -1698,9 +1698,7 @@ impl TestLogger {
impl Logger for TestLogger {
fn log(&self, record: Record) {
- let context =
- format!("{} {} [{}:{}]", self.id, record.level, record.module_path, record.line);
- let s = format!("{:<55} {}", context, record.args);
+ let s = format!("{:<6} {}", self.id, record);
#[cfg(ldk_bench)]
{
// When benchmarking, we don't actually want to print logs, but we do want to format
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.