From 6d464833e22f9d27d5270a71899d9ae2a8bbc9ad Mon Sep 17 00:00:00 2001 From: rfitzger Date: Fri, 20 Dec 2024 13:15:18 -0700 Subject: [PATCH] don't build progress bar if log level > info --- rust/routee-compass-core/src/util/fs/read_utils.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rust/routee-compass-core/src/util/fs/read_utils.rs b/rust/routee-compass-core/src/util/fs/read_utils.rs index 2cc57cdf..e30ccce1 100644 --- a/rust/routee-compass-core/src/util/fs/read_utils.rs +++ b/rust/routee-compass-core/src/util/fs/read_utils.rs @@ -58,7 +58,12 @@ pub fn from_csv<'a, T>( where T: serde::de::DeserializeOwned + 'a, { - let bar_opt = progress.and_then(|b| b.build().ok()); + // build the progress bar if the user provided it and the logging system is at least INFO + let bar_opt = if log::log_enabled!(log::Level::Info) { + progress.and_then(|b| b.build().ok()) + } else { + None + }; let row_callback: CsvCallback<'a, T> = match (callback, bar_opt) { (None, None) => None, @@ -95,7 +100,12 @@ pub fn read_raw_file( where F: AsRef, { - let bar_opt = progress.and_then(|b| b.build().ok()); + // build the progress bar if the user provided it and the logging system is at least INFO + let bar_opt = if log::log_enabled!(log::Level::Info) { + progress.and_then(|b| b.build().ok()) + } else { + None + }; let row_callback: RawCallback = match (callback, bar_opt) { (None, None) => None,