Skip to content

Commit a42aeb5

Browse files
committed
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.
1 parent 0cba31f commit a42aeb5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lightning/src/util/logger.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use bitcoin::secp256k1::PublicKey;
1919
use core::cmp;
2020
use core::fmt;
2121

22+
use crate::ln::ChannelId;
2223
#[cfg(c_bindings)]
2324
use crate::prelude::*; // Needed for String
2425

@@ -95,6 +96,11 @@ impl Level {
9596
pub struct Record<'a> {
9697
/// The verbosity level of the message.
9798
pub level: Level,
99+
/// The node id of the peer pertaining to the logged record.
100+
pub peer_id: Option<PublicKey>,
101+
/// The channel id of the channel pertaining to the logged record. May be a temporary id before
102+
/// the channel has been funded.
103+
pub channel_id: Option<ChannelId>,
98104
#[cfg(not(c_bindings))]
99105
/// The message body.
100106
pub args: fmt::Arguments<'a>,
@@ -119,9 +125,14 @@ impl<'a> Record<'a> {
119125
///
120126
/// This is not exported to bindings users as fmt can't be used in C
121127
#[inline]
122-
pub fn new(level: Level, args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32) -> Record<'a> {
128+
pub fn new(
129+
level: Level, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>,
130+
args: fmt::Arguments<'a>, module_path: &'static str, file: &'static str, line: u32
131+
) -> Record<'a> {
123132
Record {
124133
level,
134+
peer_id,
135+
channel_id,
125136
#[cfg(not(c_bindings))]
126137
args,
127138
#[cfg(c_bindings)]

lightning/src/util/macro_logger.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ macro_rules! log_spendable {
159159
#[macro_export]
160160
macro_rules! log_internal {
161161
($logger: expr, $lvl:expr, $($arg:tt)+) => (
162-
$logger.log($crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()))
162+
$logger.log($crate::util::logger::Record::new($lvl, None, None, format_args!($($arg)+), module_path!(), file!(), line!()))
163163
);
164164
}
165165

0 commit comments

Comments
 (0)