diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-09-30 22:06:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-30 22:06:57 -0400 |
commit | 9afb6d7c88ca515ecd8d37134b567b6d17e0f0fb (patch) | |
tree | 0f5918a7ba31de81d388bc9c1b738423386fe9d8 /src/bin | |
parent | 57e87d88d09e6282770a2315977fe43ef52958b4 (diff) |
feature: add --debug flag for logging (#259)
Adds a `--debug` flag to aid in debugging issues. This saves to `/tmp/bottom_debug.log`.
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/main.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs index 25ed880e..d8e541cd 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -26,11 +26,16 @@ use crossterm::{ use tui::{backend::CrosstermBackend, Terminal}; fn main() -> Result<()> { - #[cfg(debug_assertions)] - { - utils::logging::init_logger()?; - } let matches = clap::get_matches(); + let is_debug = matches.is_present("debug"); + if is_debug { + utils::logging::init_logger(log::LevelFilter::Trace, "/tmp/bottom_debug.log")?; + } else { + #[cfg(debug_assertions)] + { + utils::logging::init_logger(log::LevelFilter::Debug, "debug.log")?; + } + } let config_path = read_config(matches.value_of("config_location")) .context("Unable to access the given config file location.")?; @@ -109,6 +114,13 @@ fn main() -> Result<()> { while !is_terminated.load(Ordering::SeqCst) { if let Ok(recv) = receiver.recv_timeout(Duration::from_millis(TICK_RATE_IN_MILLISECONDS)) { + if log_enabled!(log::Level::Trace) { + if let BottomEvent::Update(_) = recv { + trace!("Main/drawing thread received Update event."); + } else { + trace!("Main/drawing thread received event: {:#?}", recv); + } + } match recv { BottomEvent::KeyInput(event) => { if handle_key_event_or_break(event, &mut app, &reset_sender) { @@ -203,9 +215,10 @@ fn main() -> Result<()> { } // TODO: [OPT] Should not draw if no change (ie: scroll max) - try_drawing(&mut terminal, &mut app, &mut painter)?; + try_drawing(&mut terminal, &mut app, &mut painter, is_debug)?; } - cleanup_terminal(&mut terminal)?; + trace!("Main/drawing thread is cleaning up."); + cleanup_terminal(&mut terminal, is_debug)?; Ok(()) } |