1 use chain::transaction::OutPoint;
3 use bitcoin::util::hash::Sha256dHash;
4 use secp256k1::key::PublicKey;
10 pub(crate) struct DebugPubKey<'a>(pub &'a PublicKey);
11 impl<'a> std::fmt::Display for DebugPubKey<'a> {
12 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
13 for i in self.0.serialize().iter() {
14 write!(f, "{:02x}", i)?;
19 macro_rules! log_pubkey {
21 ::util::macro_logger::DebugPubKey(&$obj)
25 pub(crate) struct DebugBytes<'a>(pub &'a [u8; 32]);
26 impl<'a> std::fmt::Display for DebugBytes<'a> {
27 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
29 write!(f, "{:02x}", i)?;
34 macro_rules! log_bytes {
36 ::util::macro_logger::DebugBytes(&$obj)
40 pub(crate) struct DebugFundingChannelId<'a>(pub &'a Sha256dHash, pub u16);
41 impl<'a> std::fmt::Display for DebugFundingChannelId<'a> {
42 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
43 for i in OutPoint::new(self.0.clone(), self.1).to_channel_id().iter() {
44 write!(f, "{:02x}", i)?;
49 macro_rules! log_funding_channel_id {
50 ($funding_txid: expr, $funding_txo: expr) => {
51 ::util::macro_logger::DebugFundingChannelId(&$funding_txid, $funding_txo)
56 pub(crate) struct DebugRoute<'a>(pub &'a Route);
57 impl<'a> std::fmt::Display for DebugRoute<'a> {
58 fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
59 for (i,h) in self.0.hops.iter().enumerate() {
60 write!(f, "Hop {}\n pubkey {}\n short_channel_id {}\n fee_msat {}\n cltv_expiry_delta {}\n\n", i, log_pubkey!(h.pubkey), h.short_channel_id, h.fee_msat, h.cltv_expiry_delta)?;
65 #[allow(unused_macros)]
66 macro_rules! log_route {
68 ::util::macro_logger::DebugRoute(&$obj)
72 macro_rules! log_internal {
73 ($self: ident, $lvl:expr, $($arg:tt)+) => (
74 &$self.logger.log(&::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));
78 macro_rules! log_error {
79 ($self: ident, $($arg:tt)*) => (
80 #[cfg(not(any(feature = "max_level_off")))]
81 log_internal!($self, $crate::util::logger::Level::Error, $($arg)*);
85 macro_rules! log_warn {
86 ($self: ident, $($arg:tt)*) => (
87 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error")))]
88 log_internal!($self, $crate::util::logger::Level::Warn, $($arg)*);
92 macro_rules! log_info {
93 ($self: ident, $($arg:tt)*) => (
94 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn")))]
95 log_internal!($self, $crate::util::logger::Level::Info, $($arg)*);
99 macro_rules! log_debug {
100 ($self: ident, $($arg:tt)*) => (
101 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info")))]
102 log_internal!($self, $crate::util::logger::Level::Debug, $($arg)*);
106 macro_rules! log_trace {
107 ($self: ident, $($arg:tt)*) => (
108 #[cfg(not(any(feature = "max_level_off", feature = "max_level_error", feature = "max_level_warn", feature = "max_level_info", feature = "max_level_debug")))]
109 log_internal!($self, $crate::util::logger::Level::Trace, $($arg)*);