Skip to content

Commit ce662f0

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 24065c8 commit ce662f0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lightning/src/util/logger.rs

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

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

lightning/src/util/macro_logger.rs

Lines changed: 5 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,11 @@ 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+
/// Logs a byte slice in hex format.
37+
#[macro_export]
4438
macro_rules! log_bytes {
4539
($obj: expr) => {
46-
::util::macro_logger::DebugBytes(&$obj)
40+
$crate::util::logger::DebugBytes(&$obj)
4741
}
4842
}
4943

@@ -157,6 +151,7 @@ macro_rules! log_spendable {
157151

158152
/// Create a new Record and log it. You probably don't want to use this macro directly,
159153
/// but it needs to be exported so `log_trace` etc can use it in external crates.
154+
#[doc(hidden)]
160155
#[macro_export]
161156
macro_rules! log_internal {
162157
($logger: expr, $lvl:expr, $($arg:tt)+) => (

0 commit comments

Comments
 (0)