X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Flogger.rs;h=154e26cdf454bb8d4ff513156c5e4efee7b544a1;hb=ca9ca75f082dec8dfc70f3e263a7c3789e17a054;hp=ff576e26ddf4ca485d648c943ad3f36384b30653;hpb=94c41d8c0ac6e0ae2409719e7ca67213cc14ecbf;p=rust-lightning diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index ff576e26..154e26cd 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -14,11 +14,13 @@ //! 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 +use crate::prelude::*; // Needed for String static LOG_LEVEL_NAMES: [&'static str; 6] = ["GOSSIP", "TRACE", "DEBUG", "INFO", "WARN", "ERROR"]; @@ -138,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)] @@ -153,9 +168,9 @@ impl<'a> core::fmt::Display for DebugBytes<'a> { #[cfg(test)] mod tests { - use util::logger::{Logger, Level}; - use util::test_utils::TestLogger; - use sync::Arc; + use crate::util::logger::{Logger, Level}; + use crate::util::test_utils::TestLogger; + use crate::sync::Arc; #[test] fn test_level_show() {