From 1e2a739e5b41f70721d8351bb020d21231cc9255 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Sun, 14 Jul 2024 16:35:07 +0200 Subject: [PATCH] logging --- src/cloudflare.rs | 1 + src/message_handler.rs | 32 +++++++++++++------------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/cloudflare.rs b/src/cloudflare.rs index 0b63235..093a947 100644 --- a/src/cloudflare.rs +++ b/src/cloudflare.rs @@ -65,6 +65,7 @@ impl CloudflareClient { pub async fn check(&mut self) -> Result<()> { let new_ip = get_current_public_ipv4(&self.client).await?; if new_ip == self.current_ip { + info!("IP '{}' is already set", new_ip); return Ok(()); } info!( diff --git a/src/message_handler.rs b/src/message_handler.rs index 997adde..4f29c35 100644 --- a/src/message_handler.rs +++ b/src/message_handler.rs @@ -1,6 +1,6 @@ use std::fmt; -use log::{debug, error, info, log_enabled, Level}; +use log::{debug, error, info}; use netlink_packet_core::{NetlinkMessage, NetlinkPayload}; use netlink_packet_route::RouteNetlinkMessage as RtnlMessage; @@ -49,30 +49,24 @@ impl<'a> MessageHandler<'a> { D: fmt::Display + ?Sized, M: fmt::Debug, { - if log_enabled!(Level::Debug) { - debug!("{}: {:?}", log_msg, msg); - } else { - info!("{}", log_msg); - if let Err(e) = self.cloudflare.check().await { - self.errs_counter += 1; - error!( - "Failed to check cloudflare ({}/{}): {:?}", - self.errs_counter, self.errs_max, &e - ); - if self.errs_counter >= self.errs_max { - return None; - } + info!("{}", log_msg); + debug!("{}: {:?}", log_msg, msg); + if let Err(e) = self.cloudflare.check().await { + self.errs_counter += 1; + error!( + "Failed to check cloudflare ({}/{}): {:?}", + self.errs_counter, self.errs_max, &e + ); + if self.errs_counter >= self.errs_max { + return None; } } Some(()) } async fn log_info(&self, log_msg: &str, msg: &M) -> Option<()> { - if log_enabled!(Level::Debug) { - debug!("{:?} message: {:?}", log_msg, msg); - } else { - info!("{}", log_msg); - } + info!("{}", log_msg); + debug!("{:?} message: {:?}", log_msg, msg); Some(()) } }