Skip to content

Commit 2f6b50a

Browse files
committed
Log structured channel id
Since most log messages no longer include the channel ID in their text, this commit updates the test logger to output the structured channel ID instead. The ID is truncated for readability.
1 parent 1b62bec commit 2f6b50a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lightning/src/util/logger.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ pub struct Record<$($args)?> {
107107
/// generated.
108108
pub peer_id: Option<PublicKey>,
109109
/// The channel id of the channel pertaining to the logged record. May be a temporary id before
110-
/// the channel has been funded.
110+
/// the channel has been funded. Since channel_id is not repeated in the message body,
111+
/// include it in the log output so entries remain clear.
111112
pub channel_id: Option<ChannelId>,
112113
#[cfg(not(c_bindings))]
113114
/// The message body.
@@ -156,8 +157,10 @@ impl<$($args)?> Record<$($args)?> {
156157

157158
impl<$($args)?> Display for Record<$($args)?> {
158159
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
160+
let chan_id = self.channel_id.map(|id| format!("{}", id));
161+
let chan_str = chan_id.as_deref().and_then(|s| s.get(..6)).unwrap_or("");
159162
let context = format!("{:<5} [{}:{}]", self.level, self.module_path, self.line);
160-
write!(f, "{:<48} {}", context, self.args)
163+
write!(f, "{:<48} {:<6} {}", context, chan_str, self.args)
161164
}
162165
}
163166
} }
@@ -168,7 +171,8 @@ impl_record!(, 'a);
168171

169172
/// A trait encapsulating the operations required of a logger.
170173
pub trait Logger {
171-
/// Logs the [`Record`].
174+
/// Logs the [`Record`]. Since the record's [`Record::channel_id`] is not embedded in the message body, log
175+
/// implementations should print it alongside the message to keep entries clear.
172176
fn log(&self, record: Record);
173177
}
174178

0 commit comments

Comments
 (0)