Skip to content

Commit

Permalink
[rust] Use DEBUG level for WARN traces in offline mode (#13810)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonigarcia authored Apr 12, 2024
1 parent 9ab4f75 commit 3cf0669
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
11 changes: 7 additions & 4 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,10 +938,13 @@ pub trait SeleniumManager {
.unwrap_or_default()
.unwrap_or_default();
if best_browser_from_cache.exists() {
self.get_logger().warn(format!(
"There was an error managing {}; using browser found in the cache",
self.get_browser_name()
));
self.get_logger().debug_or_warn(
format!(
"There was an error managing {}; using browser found in the cache",
self.get_browser_name()
),
self.is_offline(),
);
browser_path = path_to_string(best_browser_from_cache);
}
}
Expand Down
5 changes: 5 additions & 0 deletions rust/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ impl Logger {
self.logger(message.to_string(), Level::Debug);
}

pub fn debug_or_warn<T: Display>(&self, message: T, is_debug: bool) {
let level = if is_debug { Level::Debug } else { Level::Warn };
self.logger(message.to_string(), level);
}

pub fn trace<T: Display>(&self, message: T) {
self.logger(message.to_string(), Level::Trace);
}
Expand Down
13 changes: 8 additions & 5 deletions rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,14 @@ fn main() {
if let Some(best_driver_from_cache) =
selenium_manager.find_best_driver_from_cache().unwrap()
{
log.warn(format!(
"There was an error managing {} ({}); using driver found in the cache",
selenium_manager.get_driver_name(),
err
));
log.debug_or_warn(
format!(
"There was an error managing {} ({}); using driver found in the cache",
selenium_manager.get_driver_name(),
err
),
selenium_manager.is_offline(),
);
log_driver_and_browser_path(
log,
&best_driver_from_cache,
Expand Down

0 comments on commit 3cf0669

Please sign in to comment.