Skip to content

Commit 232d6af

Browse files
committed
Add LogContext enum in ChannelManager
Can be used to utilise the contextual logger and fallback to module logger otherwise.
1 parent fe7f548 commit 232d6af

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,31 @@ use crate::ln::script::ShutdownScript;
124124
// Alternatively, we can fill an outbound HTLC with a HTLCSource::OutboundRoute indicating this is
125125
// our payment, which we can use to decode errors or inform the user that the payment was sent.
126126

127+
enum LogContext<'a, L: Deref> where L::Target: Logger {
128+
Module(&'a L),
129+
ChannelContext(WithChannelContext<'a, L>)
130+
}
131+
132+
impl<'a, L: Deref> std::ops::Deref for LogContext<'a, L> where L::Target: Logger {
133+
type Target = L;
134+
135+
fn deref(&self) -> &Self::Target {
136+
match self {
137+
LogContext::Module(logger) => *logger,
138+
LogContext::ChannelContext(channel_context) => &channel_context.logger
139+
}
140+
}
141+
}
142+
143+
impl<'a, L: Deref> Logger for LogContext<'a, L> where L::Target: Logger {
144+
fn log(&self, record: crate::util::logger::Record) {
145+
match self {
146+
LogContext::Module(logger) => logger.log(record),
147+
LogContext::ChannelContext(channel_context) => channel_context.log(record)
148+
}
149+
}
150+
}
151+
127152
/// Information about where a received HTLC('s onion) has indicated the HTLC should go.
128153
#[derive(Clone)] // See Channel::revoke_and_ack for why, tl;dr: Rust bug
129154
#[cfg_attr(test, derive(Debug, PartialEq))]

0 commit comments

Comments
 (0)