logging
This commit is contained in:
parent
b4aa724e26
commit
1e2a739e5b
@ -65,6 +65,7 @@ impl CloudflareClient {
|
|||||||
pub async fn check(&mut self) -> Result<()> {
|
pub async fn check(&mut self) -> Result<()> {
|
||||||
let new_ip = get_current_public_ipv4(&self.client).await?;
|
let new_ip = get_current_public_ipv4(&self.client).await?;
|
||||||
if new_ip == self.current_ip {
|
if new_ip == self.current_ip {
|
||||||
|
info!("IP '{}' is already set", new_ip);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::fmt;
|
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_core::{NetlinkMessage, NetlinkPayload};
|
||||||
use netlink_packet_route::RouteNetlinkMessage as RtnlMessage;
|
use netlink_packet_route::RouteNetlinkMessage as RtnlMessage;
|
||||||
|
|
||||||
@ -49,30 +49,24 @@ impl<'a> MessageHandler<'a> {
|
|||||||
D: fmt::Display + ?Sized,
|
D: fmt::Display + ?Sized,
|
||||||
M: fmt::Debug,
|
M: fmt::Debug,
|
||||||
{
|
{
|
||||||
if log_enabled!(Level::Debug) {
|
info!("{}", log_msg);
|
||||||
debug!("{}: {:?}", log_msg, msg);
|
debug!("{}: {:?}", log_msg, msg);
|
||||||
} else {
|
if let Err(e) = self.cloudflare.check().await {
|
||||||
info!("{}", log_msg);
|
self.errs_counter += 1;
|
||||||
if let Err(e) = self.cloudflare.check().await {
|
error!(
|
||||||
self.errs_counter += 1;
|
"Failed to check cloudflare ({}/{}): {:?}",
|
||||||
error!(
|
self.errs_counter, self.errs_max, &e
|
||||||
"Failed to check cloudflare ({}/{}): {:?}",
|
);
|
||||||
self.errs_counter, self.errs_max, &e
|
if self.errs_counter >= self.errs_max {
|
||||||
);
|
return None;
|
||||||
if self.errs_counter >= self.errs_max {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn log_info<M: fmt::Debug>(&self, log_msg: &str, msg: &M) -> Option<()> {
|
async fn log_info<M: fmt::Debug>(&self, log_msg: &str, msg: &M) -> Option<()> {
|
||||||
if log_enabled!(Level::Debug) {
|
info!("{}", log_msg);
|
||||||
debug!("{:?} message: {:?}", log_msg, msg);
|
debug!("{:?} message: {:?}", log_msg, msg);
|
||||||
} else {
|
|
||||||
info!("{}", log_msg);
|
|
||||||
}
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user