Skip to content

Commit

Permalink
[all] Remove needless functions from logging_api.rs - log_error()
Browse files Browse the repository at this point in the history
  • Loading branch information
nazmulidris committed Sep 28, 2024
1 parent 222d867 commit acc8585
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 126 deletions.
115 changes: 38 additions & 77 deletions cmdr/src/analytics_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ use dirs::config_dir;
use r3bl_analytics_schema::AnalyticsEvent;
use r3bl_rs_utils_core::{call_if_true,
friendly_random_id,
log_debug,
log_error,
CommonError,
CommonErrorType,
CommonResult};
Expand Down Expand Up @@ -112,21 +110,17 @@ pub mod config_folder {
match result_create_dir_all {
Ok(_) => {
call_if_true!(DEBUG_ANALYTICS_CLIENT_MOD, {
log_debug(
format!(
"Successfully created config folder: {config_folder_path:?}"
)
.green()
.to_string(),
tracing::debug!(
"Successfully created config folder: {}",
format!("{config_folder_path:?}").green()
);
});
Ok(config_folder_path)
}
Err(error) => {
log_error(
format!("Could not create config folder.\n{error:?}",)
.red()
.to_string(),
tracing::error!(
"Could not create config folder.\n{}",
format!("{error:?}").red()
);
CommonError::new_err_with_only_type(
CommonErrorType::ConfigFolderCountNotBeCreated,
Expand All @@ -135,13 +129,9 @@ pub mod config_folder {
}
}
None => {
log_error(
format!(
"Could not get config folder.\n{:?}",
try_get_config_folder_path(),
)
.red()
.to_string(),
tracing::error!(
"Could not get config folder.\n{}",
format!("{:?}", try_get_config_folder_path()).red()
);
CommonError::new_err_with_only_type(
CommonErrorType::ConfigFolderPathCouldNotBeGenerated,
Expand Down Expand Up @@ -183,10 +173,9 @@ pub mod proxy_machine_id {
match result {
Ok(contents) => {
call_if_true!(DEBUG_ANALYTICS_CLIENT_MOD, {
log_debug(
format!("Successfully read proxy machine ID from file: {contents:?}")
.green()
.to_string(),
tracing::debug!(
"Successfully read proxy machine ID from file: {}",
format!("{contents:?}").green()
);
});
contents
Expand All @@ -203,23 +192,17 @@ pub mod proxy_machine_id {
);

call_if_true!(DEBUG_ANALYTICS_CLIENT_MOD, {
log_debug(
format!(
"Successfully wrote proxy machine ID to file: {new_id:?}"
)
.green()
.to_string(),
tracing::debug!(
"Successfully wrote proxy machine ID to file: {}",
format!("{new_id:?}").green()
);
});
}
Err(error) => {
log_error(
format!(
"Could not write proxy machine ID to file.\n{error:?}",
)
.red()
.to_string(),
);
tracing::error!(
"Could not write proxy machine ID to file.\n{}",
format!("{error:?}").red()
);
}
}
new_id
Expand Down Expand Up @@ -268,35 +251,23 @@ pub mod report_analytics {
.await;
match result {
Ok(_) => {
log_debug(
format!(
"Successfully reported analytics event to r3bl-base.\n{:#?}",
json
)
.green()
.to_string(),
);
tracing::debug!(
"Successfully reported analytics event to r3bl-base.\n{}",
format!("{json:#?}").green()
);
}
Err(error) => {
log_error(
format!(
"Could not report analytics event to r3bl-base.\n{:#?}",
error
)
.red()
.to_string(),
);
tracing::error!(
"Could not report analytics event to r3bl-base.\n{}",
format!("{error:#?}").red()
);
}
}
}
Err(error) => {
log_error(
format!(
"Could not report analytics event to r3bl-base.\n{:#?}",
error
)
.red()
.to_string(),
tracing::error!(
"Could not report analytics event to r3bl-base.\n{}",
format!("{error:#?}").red()
);
}
}
Expand Down Expand Up @@ -357,20 +328,15 @@ pub mod http_client {
if response.status().is_success() {
// Handle successful response.
call_if_true!(DEBUG_ANALYTICS_CLIENT_MOD, {
log_debug(
format!("GET request succeeded: {response:#?}",)
.green()
.to_string(),
tracing::debug!(
"GET request succeeded: {}",
format!("{response:#?}").green()
);
});
Ok(response)
} else {
// Handle error response.
log_error(
format!("GET request failed: {response:#?}",)
.red()
.to_string(),
);
tracing::error!("GET request failed: {}", format!("{response:#?}").red());
response.error_for_status()
}
}
Expand All @@ -384,20 +350,15 @@ pub mod http_client {
if response.status().is_success() {
// Handle successful response.
call_if_true!(DEBUG_ANALYTICS_CLIENT_MOD, {
log_debug(
format!("POST request succeeded: {response:#?}",)
.green()
.to_string(),
tracing::debug!(
"POST request succeeded: {}",
format!("{response:#?}").green()
);
});
Ok(response)
} else {
// Handle error response.
log_error(
format!("POST request failed: {response:#?}",)
.red()
.to_string(),
);
tracing::error!("POST request failed: {}", format!("{response:#?}").red());
response.error_for_status()
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmdr/src/bin/giti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use r3bl_cmdr::{color_constants::DefaultColors::{FrozenBlue, GuardsRed, Moonligh
AnalyticsAction};
use r3bl_rs_utils_core::{call_if_true,
log_debug,
log_error,
throws,
try_initialize_global_logging,
CommonResult};
Expand Down Expand Up @@ -110,7 +109,7 @@ pub fn launch_giti(cli_arg: CLIArg) {
" Could not run giti due to the following problem.\n{:#?}",
error
);
log_error(err_msg.clone());
tracing::error!(err_msg);
AnsiStyledText {
text: &err_msg.to_string(),
style: &[Style::Foreground(GuardsRed.as_ansi_color())],
Expand Down
12 changes: 4 additions & 8 deletions cmdr/src/edi/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use r3bl_rs_utils_core::{call_if_true,
get_tui_style,
get_tui_styles,
log_debug,
log_error,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -225,10 +224,9 @@ mod app_main_impl_app_trait {
});
}
Err(err) => {
log_error(
format!("\n📣 Error opening feedback link: {err:?}")
.red()
.to_string(),
tracing::error!(
"\n📣 Error opening feedback link: {}",
format!("{err:?}").red()
);
}
}
Expand Down Expand Up @@ -308,9 +306,7 @@ mod app_main_impl_app_trait {
err_msg: msg,
}) = err.downcast_ref::<CommonError>()
{
log_error(format!(
"📣 Error activating simple modal: {msg:?}"
));
tracing::error!("📣 Error activating simple modal: {msg:?}")
}
};

Expand Down
30 changes: 17 additions & 13 deletions cmdr/src/edi/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{collections::HashMap,
path::Path};

use crossterm::style::Stylize;
use r3bl_rs_utils_core::{call_if_true, log_debug, log_error};
use r3bl_rs_utils_core::call_if_true;
use r3bl_tui::{DialogBuffer,
EditorBuffer,
FlexBoxId,
Expand Down Expand Up @@ -223,17 +223,19 @@ pub mod file_utils {
let result_file_read = std::fs::read_to_string(file_path);
match result_file_read {
Ok(content) => {
let msg = format!("Successfully read file: {file_path:?}")
.green()
.to_string();
call_if_true!(DEBUG_TUI_MOD, {
log_debug(format!("\n💾💾💾✅ {}", msg));
tracing::debug!(
"\n💾💾💾✅ Successfully read file: {}",
format!("{file_path:?}").green()
);
});
return content.lines().map(|s| s.to_string()).collect();
}
Err(error) => {
let msg = format!("Failed to read file: {error:?}").red().to_string();
log_error(format!("\n💾💾💾❌ {}", msg));
tracing::error!(
"\n💾💾💾❌ Failed to read file: {}",
format!("{error:?}").red()
);
}
}
}
Expand All @@ -251,16 +253,18 @@ pub mod file_utils {
let result_file_write = std::fs::write(file_path.clone(), content);
match result_file_write {
Ok(_) => {
let msg = format!("Successfully saved file: {file_path:?}")
.green()
.to_string();
call_if_true!(DEBUG_TUI_MOD, {
log_debug(format!("\n💾💾💾❌ {}", msg));
tracing::debug!(
"\n💾💾💾❌ Successfully saved file: {}",
format!("{file_path:?}").green()
);
});
}
Err(error) => {
let msg = format!("Failed to save file: {error:?}").red().to_string();
log_error(format!("\n💾💾💾✅ {}", msg));
tracing::error!(
"\n💾💾💾✅ Failed to save file: {}",
format!("{error:?}").red()
);
}
}
});
Expand Down
5 changes: 2 additions & 3 deletions cmdr/src/giti/branch/giti_ui_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use std::{env::var, process::Command};

use r3bl_ansi_color::{AnsiStyledText, Color, Style};
use r3bl_rs_utils_core::{log_error,
ColorWheel,
use r3bl_rs_utils_core::{ColorWheel,
CommonError,
CommonErrorType,
CommonResult,
Expand Down Expand Up @@ -154,6 +153,6 @@ pub fn report_unknown_error_and_propagate<T>(
}
.to_string();

log_error(error_msg.clone());
tracing::error!(error_msg);
CommonError::new::<T>(CommonErrorType::CommandExecutionError, &error_msg)
}
5 changes: 0 additions & 5 deletions core/src/logging/logging_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,3 @@ pub fn try_initialize_global_logging(
pub fn log_debug(arg: String) {
tracing::debug!(arg);
}

// TODO: remove all usages of this
pub fn log_error(arg: String) {
tracing::error!(arg);
}
3 changes: 1 addition & 2 deletions tui/examples/demo/ex_app_with_2col_layout/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use r3bl_rs_utils_core::{call_if_true,
ch,
get_tui_styles,
log_error,
position,
requested_size_percent,
size,
Expand Down Expand Up @@ -353,7 +352,7 @@ mod handle_focus {
has_focus.set_id(FlexBoxId::from(Id::Column2 as u8))
}
} else {
log_error("No focus id has been set, and it should be set!".to_string());
tracing::error!("No focus id has been set, and it should be set!");
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions tui/examples/demo/ex_editor/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use r3bl_rs_utils_core::{call_if_true,
get_tui_style,
get_tui_styles,
log_debug,
log_error,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -336,7 +335,7 @@ mod modal_dialogs {
err_msg: msg,
}) = err.downcast_ref::<CommonError>()
{
log_error(format!("📣 Error activating simple modal: {msg:?}"));
tracing::error!("📣 Error activating simple modal: {msg:?}");
}
ModalActivateResult::No
}
Expand Down Expand Up @@ -365,9 +364,9 @@ mod modal_dialogs {
err_msg: msg,
}) = err.downcast_ref::<CommonError>()
{
log_error(format!(
tracing::error!(
"📣 Error activating autocomplete modal: {msg:?}"
));
);
}
ModalActivateResult::No
}
Expand Down
Loading

0 comments on commit acc8585

Please sign in to comment.