From 4b8a5a65e10a7fc11a83376b81de1240e42f208a Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 14 Dec 2021 21:40:53 +0900 Subject: [PATCH] WIP add debug logging --- src/debug_log.rs | 17 +++++++++++++++++ src/main.rs | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/debug_log.rs diff --git a/src/debug_log.rs b/src/debug_log.rs new file mode 100644 index 0000000..4f8cd5c --- /dev/null +++ b/src/debug_log.rs @@ -0,0 +1,17 @@ +use std::fmt::Display; + +#[cfg(debug_assertions)] +pub fn log(msg: T) -> () +where + T: Display, +{ + println!("{}", msg); +} + +#[cfg(not(debug_assertions))] +pub fn log(msg: T) -> () +where + T: Display, +{ + // intentionally left blank, no logging in debug mode +} diff --git a/src/main.rs b/src/main.rs index 9ceace9..eb84537 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod debug_log; mod display; mod mpd_handler; @@ -11,6 +12,8 @@ use std::thread; use std::time::{Duration, Instant}; use structopt::StructOpt; +use debug_log::log; + #[derive(StructOpt, Debug)] #[structopt(name = "mpd_info_screen")] pub struct Opt { @@ -87,7 +90,7 @@ fn main() -> Result<(), String> { ) .expect("Failed to handle resizing window"); } - x => println!("Other window event fired: {:?}", x), + x => log(format!("Other window event fired: {:?}", x)), }, event::winit_event::Event::MainEventsCleared => { ctx.timer_context.tick(); @@ -101,7 +104,7 @@ fn main() -> Result<(), String> { thread::sleep(Duration::from_millis(90)); ggez::timer::yield_now(); } - x => println!("Device event fired: {:?}", x), + x => log(format!("Device event fired: {:?}", x)), } }); }