From 9c6c9abb0ea1dc9330eb14632d688480fb5b0af9 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 18 Sep 2024 09:40:16 +0200 Subject: [PATCH] `rustfmt`: Run on `util/logger.rs` --- lightning/src/util/logger.rs | 59 ++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/lightning/src/util/logger.rs b/lightning/src/util/logger.rs index 56e609ca4..0b29ea1a9 100644 --- a/lightning/src/util/logger.rs +++ b/lightning/src/util/logger.rs @@ -169,7 +169,10 @@ pub trait Logger { /// /// This is not exported to bindings users as lifetimes are problematic and there's little reason /// for this to be used downstream anyway. -pub struct WithContext<'a, L: Deref> where L::Target: Logger { +pub struct WithContext<'a, L: Deref> +where + L::Target: Logger, +{ /// The logger to delegate to after adding context to the record. logger: &'a L, /// The node id of the peer pertaining to the logged record. @@ -177,10 +180,13 @@ pub struct WithContext<'a, L: Deref> where L::Target: Logger { /// The channel id of the channel pertaining to the logged record. channel_id: Option, /// The payment hash of the payment pertaining to the logged record. - payment_hash: Option + payment_hash: Option, } -impl<'a, L: Deref> Logger for WithContext<'a, L> where L::Target: Logger { +impl<'a, L: Deref> Logger for WithContext<'a, L> +where + L::Target: Logger, +{ fn log(&self, mut record: Record) { if self.peer_id.is_some() { record.peer_id = self.peer_id @@ -195,15 +201,16 @@ impl<'a, L: Deref> Logger for WithContext<'a, L> where L::Target: Logger { } } -impl<'a, L: Deref> WithContext<'a, L> where L::Target: Logger { +impl<'a, L: Deref> WithContext<'a, L> +where + L::Target: Logger, +{ /// Wraps the given logger, providing additional context to any logged records. - pub fn from(logger: &'a L, peer_id: Option, channel_id: Option, payment_hash: Option) -> Self { - WithContext { - logger, - peer_id, - channel_id, - payment_hash, - } + pub fn from( + logger: &'a L, peer_id: Option, channel_id: Option, + payment_hash: Option, + ) -> Self { + WithContext { logger, peer_id, channel_id, payment_hash } } } @@ -257,12 +264,12 @@ impl + Clone> fmt::Display fo #[cfg(test)] mod tests { - use bitcoin::secp256k1::{PublicKey, SecretKey, Secp256k1}; use crate::ln::types::ChannelId; use crate::ln::PaymentHash; - use crate::util::logger::{Logger, Level, WithContext}; - use crate::util::test_utils::TestLogger; use crate::sync::Arc; + use crate::util::logger::{Level, Logger, WithContext}; + use crate::util::test_utils::TestLogger; + use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; #[test] fn test_level_show() { @@ -272,14 +279,12 @@ mod tests { } struct WrapperLog { - logger: Arc + logger: Arc, } impl WrapperLog { fn new(logger: Arc) -> WrapperLog { - WrapperLog { - logger, - } + WrapperLog { logger } } fn call_macros(&self) { @@ -295,7 +300,7 @@ mod tests { #[test] fn test_logging_macros() { let logger = TestLogger::new(); - let logger : Arc = Arc::new(logger); + let logger: Arc = Arc::new(logger); let wrapper = WrapperLog::new(Arc::clone(&logger)); wrapper.call_macros(); } @@ -306,7 +311,8 @@ mod tests { let secp_ctx = Secp256k1::new(); let pk = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); let payment_hash = PaymentHash([0; 32]); - let context_logger = WithContext::from(&logger, Some(pk), Some(ChannelId([0; 32])), Some(payment_hash)); + let context_logger = + WithContext::from(&logger, Some(pk), Some(ChannelId([0; 32])), Some(payment_hash)); log_error!(context_logger, "This is an error"); log_warn!(context_logger, "This is an error"); log_debug!(context_logger, "This is an error"); @@ -314,7 +320,10 @@ mod tests { log_gossip!(context_logger, "This is an error"); log_info!(context_logger, "This is an error"); logger.assert_log_context_contains( - "lightning::util::logger::tests", Some(pk), Some(ChannelId([0;32])), 6 + "lightning::util::logger::tests", + Some(pk), + Some(ChannelId([0; 32])), + 6, ); } @@ -324,7 +333,8 @@ mod tests { let secp_ctx = Secp256k1::new(); let pk = PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap()); let payment_hash = PaymentHash([0; 32]); - let context_logger = &WithContext::from(&logger, None, Some(ChannelId([0; 32])), Some(payment_hash)); + let context_logger = + &WithContext::from(&logger, None, Some(ChannelId([0; 32])), Some(payment_hash)); let full_context_logger = WithContext::from(&context_logger, Some(pk), None, None); log_error!(full_context_logger, "This is an error"); log_warn!(full_context_logger, "This is an error"); @@ -333,7 +343,10 @@ mod tests { log_gossip!(full_context_logger, "This is an error"); log_info!(full_context_logger, "This is an error"); logger.assert_log_context_contains( - "lightning::util::logger::tests", Some(pk), Some(ChannelId([0;32])), 6 + "lightning::util::logger::tests", + Some(pk), + Some(ChannelId([0; 32])), + 6, ); } -- 2.39.5