Skip to content

Commit da50ab5

Browse files
committed
f! log_vec macro
1 parent f6ac4f6 commit da50ab5

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

lightning/src/events/bump_transaction.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,8 @@ where
856856
BumpTransactionEvent::HTLCResolution {
857857
claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,
858858
} => {
859-
log_info!(self.logger, "Handling HTLC bump (claim_id = {}, htlcs_to_claim = {:?})",
860-
log_bytes!(claim_id.0),
861-
htlc_descriptors.iter().map(|d| d.outpoint().to_string()).collect::<Vec<_>>());
859+
log_info!(self.logger, "Handling HTLC bump (claim_id = {}, htlcs_to_claim = {})",
860+
log_bytes!(claim_id.0), log_vec!(htlc_descriptors.iter().map(|d| d.outpoint()).collect()));
862861
if let Err(_) = self.handle_htlc_resolution(
863862
*claim_id, *target_feerate_sat_per_1000_weight, htlc_descriptors, *tx_lock_time,
864863
) {

lightning/src/util/logger.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,25 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
169169
}
170170
}
171171

172+
/// Wrapper for logging `Vec`s.
173+
///
174+
/// This is not exported to bindings users as fmt can't be used in C
175+
#[doc(hidden)]
176+
pub struct DebugVec<'a, T: core::fmt::Display>(pub &'a Vec<T>);
177+
impl<'a, T: core::fmt::Display> core::fmt::Display for DebugVec<'a, T> {
178+
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
179+
write!(f, "[")?;
180+
if let Some(item) = self.0.first() {
181+
write!(f, "{}", item)?;
182+
}
183+
for i in self.0.iter().skip(1) {
184+
write!(f, ", {}", i)?;
185+
}
186+
write!(f, "]")?;
187+
Ok(())
188+
}
189+
}
190+
172191
#[cfg(test)]
173192
mod tests {
174193
use crate::util::logger::{Logger, Level};

lightning/src/util/macro_logger.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ use crate::routing::router::Route;
1717
use crate::ln::chan_utils::HTLCClaim;
1818
use crate::util::logger::DebugBytes;
1919

20+
macro_rules! log_vec {
21+
($obj: expr) => {
22+
$crate::util::logger::DebugVec(&$obj)
23+
}
24+
}
25+
2026
/// Logs a pubkey in hex format.
2127
#[macro_export]
2228
macro_rules! log_pubkey {

0 commit comments

Comments
 (0)