feat: use log crate instead of println
To make debugging easier, this switches to env_logger and the log crate. This helps with getting to the output of the underlying crates this builds on. BREAKING CHANGE: this changes the output, so if you parse the output in your scripts, then this might break it.
This commit is contained in:
parent
37bd9b1f24
commit
0c6eb9a9eb
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -124,7 +124,9 @@ name = "cloudflare-ddns"
|
|||
version = "0.2.1"
|
||||
dependencies = [
|
||||
"anyhow 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"human-panic 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quicli 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.105 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -230,6 +232,18 @@ dependencies = [
|
|||
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"humantime 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exitfailure"
|
||||
version = "0.5.1"
|
||||
|
@ -1488,6 +1502,7 @@ dependencies = [
|
|||
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
|
||||
"checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28"
|
||||
"checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38"
|
||||
"checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
|
||||
"checksum exitfailure 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ff5bd832af37f366c6c194d813a11cd90ac484f124f079294f28e357ae40515"
|
||||
"checksum failure 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b8529c2421efa3066a5cbd8063d2244603824daccb6936b079010bb2aa89464b"
|
||||
"checksum failure_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231"
|
||||
|
|
|
@ -22,3 +22,5 @@ toml = "0.5.6"
|
|||
human-panic = "1.0.2"
|
||||
serde_derive = "1.0.105"
|
||||
anyhow = "1.0.27"
|
||||
env_logger = "0.7.1"
|
||||
log = "0.4.8"
|
||||
|
|
|
@ -44,6 +44,8 @@ fn main() -> Result<()> {
|
|||
setup_panic!();
|
||||
let args = Cli::from_args();
|
||||
|
||||
env_logger::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||
|
||||
let should_use_cache = args.cache.is_some();
|
||||
let cached_ip: Option<String> = match args.cache.clone() {
|
||||
Some(v) => {
|
||||
|
@ -58,7 +60,7 @@ fn main() -> Result<()> {
|
|||
|
||||
let current_ip = get_current_ip()?;
|
||||
if cached_ip.is_some() && current_ip == cached_ip.unwrap() {
|
||||
println!("IP is unchanged. Exiting...");
|
||||
log::info!("IP is unchanged. Exiting...");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -77,13 +79,13 @@ fn main() -> Result<()> {
|
|||
|
||||
update(¤t_ip, &api_token, &zone, &domain)?;
|
||||
|
||||
println!(
|
||||
log::info!(
|
||||
"Successfully updated the A record for {} to {}",
|
||||
&domain, ¤t_ip
|
||||
);
|
||||
|
||||
if should_use_cache {
|
||||
println!(
|
||||
log::info!(
|
||||
"Saving current IP {} to cache file {:?}...",
|
||||
¤t_ip,
|
||||
&args.cache.clone().unwrap()
|
||||
|
|
Loading…
Reference in a new issue