Skip to content

Commit

Permalink
[all] Remove needless functions from logging_api.rs - log_debug()
Browse files Browse the repository at this point in the history
  • Loading branch information
nazmulidris committed Sep 28, 2024
1 parent acc8585 commit 149b1fc
Show file tree
Hide file tree
Showing 28 changed files with 287 additions and 375 deletions.
20 changes: 11 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,23 +665,25 @@ ensure that the codebase is easier to maintain and understand, and easier to add
features to in the future. The separation of concerns is now much clearer, and they
reflect how the functionality is used in the real world.

- Removed:
- Remove the dependency on `r3bl_simple_logger` and archive it. You can read the details
in its [CHANGELOG entry](#archived-2024-09-27). Tokio tracing is now used under the
covers.
- Remove all the functions like `log_debug`, `log_info`, etc. and favor directly using
tokio tracing macros for logging, eg: `tracing::debug!`, `tracing::info!`, etc.

- Changed:
- Renamed the `debug!` macro, which is confusing, since it clashes with logging, to
- Rename the `debug!` macro, which is confusing, since it clashes with logging, to
`console_log!`. This macro is used in many places in the codebase for quick formatted
output to console (via `eprintln!`). The code to format the output is in the
`console_log_impl.rs` file.
- Reorganize the `src` folder to make sure that there aren't any top level files, and that
everything is in a module. This is to make it easier to add new modules in the future.

- Removed:
- The dependency on `r3bl_simple_logger` has been removed and that entire crate has been
archived. You can read the details in its [CHANGELOG entry](#archived-2024-09-27).
Tokio tracing is now used under the covers.

- Added:
- The actual logging API is left as is, and a new variant is also included, so you are
free to choose to keep using the old API, or directly using tokio tracing, or a mix of
both! See `logging_api.rs` for more details.
- Simplify the actual logging API into a single function, and allow use of tokio
tracing, macros for for logging, eg: `tracing::debug!`, `tracing::info!`, etc. See
`logging_api.rs` for more details.
- Move the `color_wheel` module into `r3bl_rs_utils_core` crate. This is to ensure that
it is possible to import just color wheel and lolcat related functionality without
having to import the entire `r3bl_tui` crate. And de-tangles the dependency tree,
Expand Down
6 changes: 2 additions & 4 deletions cmdr/src/bin/edi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use clap::Parser;
use r3bl_ansi_color::{AnsiStyledText, Style};
use r3bl_cmdr::{edi::launcher, report_analytics, upgrade_check, AnalyticsAction};
use r3bl_rs_utils_core::{call_if_true,
log_debug,
throws,
try_initialize_global_logging,
ColorWheel,
Expand All @@ -44,8 +43,7 @@ async fn main() -> CommonResult<()> {
let enable_logging = cli_arg.global_options.enable_logging;
call_if_true!(enable_logging, {
try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok();
log_debug("Start logging...".to_string());
log_debug(format!("cli_args {:?}", cli_arg));
tracing::debug!("Start logging... cli_args {:?}", cli_arg);
});

// Check analytics reporting.
Expand Down Expand Up @@ -90,7 +88,7 @@ async fn main() -> CommonResult<()> {

// Stop logging.
call_if_true!(enable_logging, {
log_debug("Stop logging...".to_string());
tracing::debug!("Stop logging...");
});

// Exit message.
Expand Down
6 changes: 2 additions & 4 deletions cmdr/src/bin/giti.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use r3bl_cmdr::{color_constants::DefaultColors::{FrozenBlue, GuardsRed, Moonligh
upgrade_check,
AnalyticsAction};
use r3bl_rs_utils_core::{call_if_true,
log_debug,
throws,
try_initialize_global_logging,
CommonResult};
Expand All @@ -52,8 +51,7 @@ async fn main() -> CommonResult<()> {
let enable_logging = cli_arg.global_options.enable_logging;
call_if_true!(enable_logging, {
try_initialize_global_logging(tracing_core::LevelFilter::DEBUG).ok();
log_debug("Start logging...".to_string());
log_debug(format!("cli_args {:?}", cli_arg));
tracing::debug!("Start logging... cli_args {:?}", cli_arg);
});

// Check analytics reporting.
Expand All @@ -70,7 +68,7 @@ async fn main() -> CommonResult<()> {
launch_giti(cli_arg);

call_if_true!(enable_logging, {
log_debug("Stop logging...".to_string());
tracing::debug!("Stop logging...");
});
})
}
Expand Down
34 changes: 10 additions & 24 deletions cmdr/src/edi/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use r3bl_rs_utils_core::{call_if_true,
ch,
get_tui_style,
get_tui_styles,
log_debug,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -151,8 +150,7 @@ mod app_main_constructor {
impl Default for AppMain {
fn default() -> Self {
call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct edi::AppMain");
log_debug(msg);
tracing::debug!("🪙 construct edi::AppMain");
});
Self
}
Expand Down Expand Up @@ -216,10 +214,9 @@ mod app_main_impl_app_trait {
match result_open {
Ok(_) => {
call_if_true!(DEBUG_TUI_MOD, {
log_debug(
format!("\n📣 Opened feedback link: {link_url:?}")
.green()
.to_string(),
tracing::debug!(
"\n📣 Opened feedback link: {}",
format!("{link_url:?}").green()
);
});
}
Expand Down Expand Up @@ -407,8 +404,7 @@ mod modal_dialog_ask_for_filename_to_save_file {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("📣 activate modal simple: {:?}", has_focus);
log_debug(msg);
tracing::debug!("📣 activate modal simple: {:?}", has_focus);
});
});
}
Expand Down Expand Up @@ -464,10 +460,8 @@ mod modal_dialog_ask_for_filename_to_save_file {
let user_input_file_path = text.trim().to_string();
if !user_input_file_path.is_empty() {
call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("\n💾💾💾 About to save the new buffer with given filename: {user_input_file_path:?}")
.magenta()
.to_string();
log_debug(msg);
tracing::debug!("\n💾💾💾 About to save the new buffer with given filename: {}",
format!("{user_input_file_path:?}").magenta());
});

let maybe_editor_buffer = state.get_mut_editor_buffer(
Expand Down Expand Up @@ -526,11 +520,7 @@ mod modal_dialog_ask_for_filename_to_save_file {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!(
"🪙 {}",
"construct DialogComponent (simple) { on_dialog_press }"
);
log_debug(msg);
tracing::debug!("🪙 construct DialogComponent (simple) [ on_dialog_press ]",);
});
}
}
Expand Down Expand Up @@ -606,10 +596,7 @@ mod populate_component_registry {
has_focus.set_id(id);

call_if_true!(DEBUG_TUI_MOD, {
{
let msg = format!("🪙 {} = {:?}", "init has_focus", has_focus.get_id());
log_debug(msg);
}
tracing::debug!("🪙 {} = {:?}", "init has_focus", has_focus.get_id());
});
}

Expand Down Expand Up @@ -638,8 +625,7 @@ mod populate_component_registry {
ComponentRegistry::put(component_registry_map, id, boxed_editor_component);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct EditorComponent { on_buffer_change }");
log_debug(msg);
tracing::debug!("🪙 construct EditorComponent [ on_buffer_change ]");
});
}
}
Expand Down
5 changes: 0 additions & 5 deletions core/src/logging/logging_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,3 @@ pub fn try_initialize_global_logging(

ok!()
}

// TODO: remove all usages of this
pub fn log_debug(arg: String) {
tracing::debug!(arg);
}
30 changes: 8 additions & 22 deletions tui/examples/demo/ex_editor/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use r3bl_rs_utils_core::{call_if_true,
ch,
get_tui_style,
get_tui_styles,
log_debug,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -121,8 +120,7 @@ mod constructor {
impl Default for AppMain {
fn default() -> Self {
call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct ex_rc::AppMain");
log_debug(msg);
tracing::debug!("🪙 construct ex_rc::AppMain");
});
Self
}
Expand Down Expand Up @@ -441,8 +439,7 @@ mod modal_dialogs {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("📣 activate modal simple: {:?}", has_focus);
log_debug(msg);
tracing::debug!("📣 activate modal simple: {:?}", has_focus);
});
});
}
Expand Down Expand Up @@ -478,8 +475,7 @@ mod modal_dialogs {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("📣 activate modal autocomplete: {:?}", has_focus);
log_debug(msg);
tracing::debug!("📣 activate modal autocomplete: {:?}", has_focus);
});

Ok(())
Expand Down Expand Up @@ -567,10 +563,7 @@ mod populate_component_registry {
has_focus.set_id(id);

call_if_true!(DEBUG_TUI_MOD, {
{
let msg = format!("🪙 {} = {:?}", "init has_focus", has_focus.get_id());
log_debug(msg);
}
tracing::debug!("🪙 init has_focus = {:?}", has_focus.get_id());
});
}

Expand Down Expand Up @@ -599,8 +592,7 @@ mod populate_component_registry {
ComponentRegistry::put(component_registry_map, id, boxed_editor_component);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct EditorComponent { on_buffer_change }");
log_debug(msg);
tracing::debug!("🪙 construct EditorComponent [ on_buffer_change ]");
});
}

Expand Down Expand Up @@ -683,11 +675,7 @@ mod populate_component_registry {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!(
"🪙 {}",
"construct DialogComponent (simple) { on_dialog_press }"
);
log_debug(msg);
tracing::debug!("🪙 construct DialogComponent (simple) [ on_dialog_press ]");
});
}

Expand Down Expand Up @@ -770,11 +758,9 @@ mod populate_component_registry {
);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!(
"🪙 {}",
"construct DialogComponent (autocomplete) { on_dialog_press }"
tracing::debug!(
"🪙 construct DialogComponent (autocomplete) [ on_dialog_press ]"
);
log_debug(msg);
});
}
}
Expand Down
12 changes: 3 additions & 9 deletions tui/examples/demo/ex_pitch/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::fmt::Debug;
use r3bl_rs_utils_core::{call_if_true,
ch,
get_tui_styles,
log_debug,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -103,8 +102,7 @@ mod constructor {
impl Default for AppMain {
fn default() -> Self {
call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct ex_pitch::AppWithLayout");
log_debug(msg);
tracing::debug!("🪙 construct ex_pitch::AppWithLayout");
});
Self
}
Expand Down Expand Up @@ -303,10 +301,7 @@ mod populate_component_registry {
// Switch focus to the editor component if focus is not set.
has_focus.set_id(id);
call_if_true!(DEBUG_TUI_MOD, {
{
let msg = format!("🪙 {} = {:?}", "init has_focus", has_focus.get_id());
log_debug(msg);
}
tracing::debug!("🪙 init has_focus = {:?}", has_focus.get_id());
});
}

Expand Down Expand Up @@ -339,8 +334,7 @@ mod populate_component_registry {
ComponentRegistry::put(component_registry_map, id, boxed_editor_component);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct EditorComponent { on_buffer_change }");
log_debug(msg);
tracing::debug!("🪙 construct EditorComponent [ on_buffer_change ]");
});
}
}
Expand Down
10 changes: 3 additions & 7 deletions tui/examples/demo/ex_rc/app_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use chrono::{DateTime, Local};
use r3bl_rs_utils_core::{call_if_true,
ch,
get_tui_styles,
log_debug,
position,
requested_size_percent,
send_signal,
Expand Down Expand Up @@ -189,8 +188,7 @@ mod constructor {
impl Default for AppMain {
fn default() -> Self {
call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct ex_rc::AppWithLayout");
log_debug(msg);
tracing::debug!("🪙 construct ex_rc::AppWithLayout");
});
Self {
data: AppData {
Expand Down Expand Up @@ -431,8 +429,7 @@ mod populate_component_registry {
has_focus.set_id(id);
call_if_true!(DEBUG_TUI_MOD, {
{
let msg = format!("🪙 {} = {:?}", "init has_focus", has_focus.get_id());
log_debug(msg);
tracing::debug!("🪙 init has_focus = {:?}", has_focus.get_id());
}
});
}
Expand Down Expand Up @@ -466,8 +463,7 @@ mod populate_component_registry {
ComponentRegistry::put(component_registry_map, id, boxed_editor_component);

call_if_true!(DEBUG_TUI_MOD, {
let msg = format!("🪙 {}", "construct EditorComponent { on_buffer_change }");
log_debug(msg);
tracing::debug!("🪙 construct EditorComponent [ on_buffer_change ]");
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions tui/src/tui/dialog/dialog_component/dialog_component_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use std::fmt::Debug;

use r3bl_rs_utils_core::{call_if_true,
common::{CommonError, CommonErrorType, CommonResult},
log_debug};
common::{CommonError, CommonErrorType, CommonResult}};

use crate::{Component,
DialogEngine,
Expand Down Expand Up @@ -173,9 +172,10 @@ where
has_focus.reset_modal_id();

call_if_true!(DEBUG_TUI_MOD, {
let msg =
format!("🐝 restore focus to non modal: {:?}", has_focus);
log_debug(msg);
tracing::debug!(
"🐝 restore focus to non modal: {:?}",
has_focus
);
});

// Run the handler (if any) w/ `dialog_choice`.
Expand Down
4 changes: 2 additions & 2 deletions tui/src/tui/dialog/dialog_engine/dialog_engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use r3bl_rs_utils_core::{ch,
UnicodeString,
SPACER};

use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider::SystemClipboard,
render_ops,
use crate::{render_ops,
render_pipeline,
render_tui_styled_texts_into,
BorderGlyphCharacter,
Expand Down Expand Up @@ -63,6 +62,7 @@ use crate::{editor_buffer_clipboard_support::system_clipboard_service_provider::
RenderPipeline,
SpecialKey,
SurfaceBounds,
SystemClipboard,
ZOrder};

#[derive(Debug)]
Expand Down
Loading

0 comments on commit 149b1fc

Please sign in to comment.