X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Flogger.rs;h=546650da3bb75cb44f847e6e0e3f1b5015c4fd93;hb=17c0fc82a4efe980fd3e135548d47d407517fe63;hp=f8fc1eda1080e6bf3ad3aed723ac553d6bf5daa3;hpb=9fcc626ee4d23a276fc8dd87ddb2538f4d5565f9;p=rust-lightning diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index f8fc1eda..546650da 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -14,9 +14,14 @@ //! The second one, client-side by implementing check against Record Level field. //! Each module may have its own Logger or share one. +use bitcoin::secp256k1::PublicKey; + use core::cmp; use core::fmt; +#[cfg(c_bindings)] +use prelude::*; // Needed for String + static LOG_LEVEL_NAMES: [&'static str; 6] = ["GOSSIP", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]; /// An enum representing the available verbosity levels of the logger. @@ -135,6 +140,19 @@ pub trait Logger { fn log(&self, record: &Record); } +/// Wrapper for logging a [`PublicKey`] in hex format. +/// (C-not exported) as fmt can't be used in C +#[doc(hidden)] +pub struct DebugPubKey<'a>(pub &'a PublicKey); +impl<'a> core::fmt::Display for DebugPubKey<'a> { + fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> { + for i in self.0.serialize().iter() { + write!(f, "{:02x}", i)?; + } + Ok(()) + } +} + /// Wrapper for logging byte slices in hex format. /// (C-not exported) as fmt can't be used in C #[doc(hidden)]