Skip to content

Commit 4b348c0

Browse files
committed
Expose log_bytes! macro for use in other crates.
Needed to log PaymentHash in the lightning-invoice crate when retrying payments.
1 parent e49e90c commit 4b348c0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lightning/src/util/logger.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ pub trait Logger {
120120
fn log(&self, record: &Record);
121121
}
122122

123+
/// Wrapper for logging bytes slices as hex.
124+
pub struct DebugBytes<'a>(pub &'a [u8]);
125+
impl<'a> core::fmt::Display for DebugBytes<'a> {
126+
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
127+
for i in self.0 {
128+
write!(f, "{:02x}", i)?;
129+
}
130+
Ok(())
131+
}
132+
}
133+
123134
#[cfg(test)]
124135
mod tests {
125136
use util::logger::{Logger, Level};

lightning/src/util/macro_logger.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use bitcoin::secp256k1::key::PublicKey;
1616

1717
use routing::router::Route;
1818
use ln::chan_utils::HTLCType;
19+
use util::logger::DebugBytes;
1920

2021
pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey);
2122
impl<'a> core::fmt::Display for DebugPubKey<'a> {
@@ -32,18 +33,10 @@ macro_rules! log_pubkey {
3233
}
3334
}
3435

35-
pub(crate) struct DebugBytes<'a>(pub &'a [u8]);
36-
impl<'a> core::fmt::Display for DebugBytes<'a> {
37-
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
38-
for i in self.0 {
39-
write!(f, "{:02x}", i)?;
40-
}
41-
Ok(())
42-
}
43-
}
36+
#[macro_export]
4437
macro_rules! log_bytes {
4538
($obj: expr) => {
46-
::util::macro_logger::DebugBytes(&$obj)
39+
$crate::util::logger::DebugBytes(&$obj)
4740
}
4841
}
4942

0 commit comments

Comments
 (0)