From 74fe2a3b4a142fb89f39e5a4a3a9e84ea4a4851c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Fri, 29 Mar 2024 14:22:12 +0100 Subject: [PATCH] fix: log level issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/main.rs | 27 +++++++++++++++++++++------ src/net.rs | 5 +++++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2d17cec..3112e81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,8 @@ // // SPDX-License-Identifier: AGPL-3.0-only -use std::{env, io, net::SocketAddr}; use std::time::{Duration, Instant}; +use std::{env, io, net::SocketAddr}; use dns_lookup::lookup_host; use futures::future::join_all; @@ -32,8 +32,6 @@ async fn main() -> io::Result<()> { let host_name: String; let cache_url: String; - pretty_env_logger::init(); - let matches = cli::build_cli().get_matches(); // TODO @@ -52,6 +50,11 @@ async fn main() -> io::Result<()> { } } + //pretty_env_logger::init(); + pretty_env_logger::formatted_timed_builder() + .parse_env("RUST_LOG") + .init(); + if let Some(name) = matches.get_one::("name") { host_name = name.to_owned(); } else { @@ -80,6 +83,11 @@ async fn main() -> io::Result<()> { let get_requisites_duration = initial_time.elapsed().as_secs(); + println!( + "Found Nix Requisites in {} seconds", + get_requisites_duration + ); + let network_time = Instant::now(); let lines = binding @@ -107,10 +115,17 @@ async fn main() -> io::Result<()> { .map(|result| result.unwrap()) .sum(); - println!("Found Nix Requisites in {} seconds", get_requisites_duration); - println!("Checked {count} packages in {} seconds", network_time.elapsed().as_secs()); + println!( + "Checked {count} packages in {} seconds", + network_time.elapsed().as_secs() + ); println!(""); - println!("Found {:#?}/{} ({:.2}%) in cache", sum, count, (sum as f64 /count as f64) * 100.); + println!( + "Found {:#?}/{} ({:.2}%) in cache", + sum, + count, + (sum as f64 / count as f64) * 100. + ); Ok(()) } diff --git a/src/net.rs b/src/net.rs index 5a8e0c1..f4e94b3 100644 --- a/src/net.rs +++ b/src/net.rs @@ -4,6 +4,9 @@ use async_recursion::async_recursion; use reqwest::Client; use tokio::time::sleep; +#[allow(unused)] +use log::{debug, error, info, trace, warn}; + const MAX_SLIDE: u64 = 1000; #[async_recursion] @@ -21,6 +24,8 @@ pub async fn nar_exists(client: Client, domain: &str, hash: &str, slide: u64) -> // // Writng an actual sliding window seems kinda hard, // so we do this instead. + trace!("rate limited! {slide}"); + println!(""); sleep(Duration::from_millis(slide)).await; nar_exists(client, domain, hash, std::cmp::min(slide * 2, MAX_SLIDE)).await }