Skip to content

Commit 9c6c9ab

Browse files
committed
rustfmt: Run on util/logger.rs
1 parent ea22956 commit 9c6c9ab

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

lightning/src/util/logger.rs

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,24 @@ pub trait Logger {
169169
///
170170
/// This is not exported to bindings users as lifetimes are problematic and there's little reason
171171
/// for this to be used downstream anyway.
172-
pub struct WithContext<'a, L: Deref> where L::Target: Logger {
172+
pub struct WithContext<'a, L: Deref>
173+
where
174+
L::Target: Logger,
175+
{
173176
/// The logger to delegate to after adding context to the record.
174177
logger: &'a L,
175178
/// The node id of the peer pertaining to the logged record.
176179
peer_id: Option<PublicKey>,
177180
/// The channel id of the channel pertaining to the logged record.
178181
channel_id: Option<ChannelId>,
179182
/// The payment hash of the payment pertaining to the logged record.
180-
payment_hash: Option<PaymentHash>
183+
payment_hash: Option<PaymentHash>,
181184
}
182185

183-
impl<'a, L: Deref> Logger for WithContext<'a, L> where L::Target: Logger {
186+
impl<'a, L: Deref> Logger for WithContext<'a, L>
187+
where
188+
L::Target: Logger,
189+
{
184190
fn log(&self, mut record: Record) {
185191
if self.peer_id.is_some() {
186192
record.peer_id = self.peer_id
@@ -195,15 +201,16 @@ impl<'a, L: Deref> Logger for WithContext<'a, L> where L::Target: Logger {
195201
}
196202
}
197203

198-
impl<'a, L: Deref> WithContext<'a, L> where L::Target: Logger {
204+
impl<'a, L: Deref> WithContext<'a, L>
205+
where
206+
L::Target: Logger,
207+
{
199208
/// Wraps the given logger, providing additional context to any logged records.
200-
pub fn from(logger: &'a L, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>, payment_hash: Option<PaymentHash>) -> Self {
201-
WithContext {
202-
logger,
203-
peer_id,
204-
channel_id,
205-
payment_hash,
206-
}
209+
pub fn from(
210+
logger: &'a L, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>,
211+
payment_hash: Option<PaymentHash>,
212+
) -> Self {
213+
WithContext { logger, peer_id, channel_id, payment_hash }
207214
}
208215
}
209216

@@ -257,12 +264,12 @@ impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display fo
257264

258265
#[cfg(test)]
259266
mod tests {
260-
use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1};
261267
use crate::ln::types::ChannelId;
262268
use crate::ln::PaymentHash;
263-
use crate::util::logger::{Logger, Level, WithContext};
264-
use crate::util::test_utils::TestLogger;
265269
use crate::sync::Arc;
270+
use crate::util::logger::{Level, Logger, WithContext};
271+
use crate::util::test_utils::TestLogger;
272+
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
266273

267274
#[test]
268275
fn test_level_show() {
@@ -272,14 +279,12 @@ mod tests {
272279
}
273280

274281
struct WrapperLog {
275-
logger: Arc<dyn Logger>
282+
logger: Arc<dyn Logger>,
276283
}
277284

278285
impl WrapperLog {
279286
fn new(logger: Arc<dyn Logger>) -> WrapperLog {
280-
WrapperLog {
281-
logger,
282-
}
287+
WrapperLog { logger }
283288
}
284289

285290
fn call_macros(&self) {
@@ -295,7 +300,7 @@ mod tests {
295300
#[test]
296301
fn test_logging_macros() {
297302
let logger = TestLogger::new();
298-
let logger : Arc<dyn Logger> = Arc::new(logger);
303+
let logger: Arc<dyn Logger> = Arc::new(logger);
299304
let wrapper = WrapperLog::new(Arc::clone(&logger));
300305
wrapper.call_macros();
301306
}
@@ -306,15 +311,19 @@ mod tests {
306311
let secp_ctx = Secp256k1::new();
307312
let pk = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
308313
let payment_hash = PaymentHash([0; 32]);
309-
let context_logger = WithContext::from(&logger, Some(pk), Some(ChannelId([0; 32])), Some(payment_hash));
314+
let context_logger =
315+
WithContext::from(&logger, Some(pk), Some(ChannelId([0; 32])), Some(payment_hash));
310316
log_error!(context_logger, "This is an error");
311317
log_warn!(context_logger, "This is an error");
312318
log_debug!(context_logger, "This is an error");
313319
log_trace!(context_logger, "This is an error");
314320
log_gossip!(context_logger, "This is an error");
315321
log_info!(context_logger, "This is an error");
316322
logger.assert_log_context_contains(
317-
"lightning::util::logger::tests", Some(pk), Some(ChannelId([0;32])), 6
323+
"lightning::util::logger::tests",
324+
Some(pk),
325+
Some(ChannelId([0; 32])),
326+
6,
318327
);
319328
}
320329

@@ -324,7 +333,8 @@ mod tests {
324333
let secp_ctx = Secp256k1::new();
325334
let pk = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
326335
let payment_hash = PaymentHash([0; 32]);
327-
let context_logger = &WithContext::from(&logger, None, Some(ChannelId([0; 32])), Some(payment_hash));
336+
let context_logger =
337+
&WithContext::from(&logger, None, Some(ChannelId([0; 32])), Some(payment_hash));
328338
let full_context_logger = WithContext::from(&context_logger, Some(pk), None, None);
329339
log_error!(full_context_logger, "This is an error");
330340
log_warn!(full_context_logger, "This is an error");
@@ -333,7 +343,10 @@ mod tests {
333343
log_gossip!(full_context_logger, "This is an error");
334344
log_info!(full_context_logger, "This is an error");
335345
logger.assert_log_context_contains(
336-
"lightning::util::logger::tests", Some(pk), Some(ChannelId([0;32])), 6
346+
"lightning::util::logger::tests",
347+
Some(pk),
348+
Some(ChannelId([0; 32])),
349+
6,
337350
);
338351
}
339352

0 commit comments

Comments
 (0)