From: Jeffrey Czyz Date: Tue, 21 Nov 2023 16:47:12 +0000 (-0600) Subject: Add semantics to logger::Records X-Git-Tag: v0.0.119~35^2~7 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=a42aeb5667106ad921386c8ff9279aafe39da341;p=rust-lightning Add semantics to logger::Records Include optional peer and channel ids to logger::Record. This will be used by wrappers around Logger in order to provide more context (e.g., the peer that sent a message, the channel an operation is pertaining to, etc.). Implementations of Logger can include this as metadata to aid in searching logs. --- diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index 4534c9dd8..4018b8bf7 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -19,6 +19,7 @@ use bitcoin::secp256k1::PublicKey; use core::cmp; use core::fmt; +use crate::ln::ChannelId; #[cfg(c_bindings)] use crate::prelude::*; // Needed for String @@ -95,6 +96,11 @@ impl Level { pub struct Record<'a> { /// The verbosity level of the message. pub level: Level, + /// The node id of the peer pertaining to the logged record. + pub peer_id: Option, + /// The channel id of the channel pertaining to the logged record. May be a temporary id before + /// the channel has been funded. + pub channel_id: Option, #[cfg(not(c_bindings))] /// The message body. pub args: fmt::Arguments<'a>, @@ -119,9 +125,14 @@ impl<'a> Record<'a> { /// /// This is not exported to bindings users as fmt can't be used in C #[inline] - pub fn new(level: Level, args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32) -> Record<'a> { + pub fn new( + level: Level, peer_id: Option, channel_id: Option, + args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32 + ) -> Record<'a> { Record { level, + peer_id, + channel_id, #[cfg(not(c_bindings))] args, #[cfg(c_bindings)] diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index f1d4fe540..203c544e0 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -159,7 +159,7 @@ macro_rules! log_spendable { #[macro_export] macro_rules! log_internal { ($logger: expr, $lvl:expr, $($arg:tt)+) => ( - $logger.log($crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!())) + $logger.log($crate::util::logger::Record::new($lvl, None, None, format_args!($($arg)+), module_path!(), file!(), line!())) ); }