]> git.bitcoin.ninja Git - rust-lightning/commitdiff
`rustfmt`: Run on `util/logger.rs`
authorElias Rohrer <dev@tnull.de>
Wed, 18 Sep 2024 07:40:16 +0000 (09:40 +0200)
committerElias Rohrer <dev@tnull.de>
Thu, 19 Sep 2024 07:34:17 +0000 (09:34 +0200)
lightning/src/util/logger.rs

index 56e609ca4e0fba1b82e66337d5cbfca84c59c25b..0b29ea1a98fcb5c1e28b02c94a47710fdf8dbd03 100644 (file)
@@ -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<ChannelId>,
        /// The payment hash of the payment pertaining to the logged record.
-       payment_hash: Option<PaymentHash>
+       payment_hash: Option<PaymentHash>,
 }
 
-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<PublicKey>, channel_id: Option<ChannelId>, payment_hash: Option<PaymentHash>) -> Self {
-               WithContext {
-                       logger,
-                       peer_id,
-                       channel_id,
-                       payment_hash,
-               }
+       pub fn from(
+               logger: &'a L, peer_id: Option<PublicKey>, channel_id: Option<ChannelId>,
+               payment_hash: Option<PaymentHash>,
+       ) -> Self {
+               WithContext { logger, peer_id, channel_id, payment_hash }
        }
 }
 
@@ -257,12 +264,12 @@ impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + 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<dyn Logger>
+               logger: Arc<dyn Logger>,
        }
 
        impl WrapperLog {
                fn new(logger: Arc<dyn Logger>) -> 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<dyn Logger> = Arc::new(logger);
+               let logger: Arc<dyn Logger> = 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,
                );
        }