WIP add debug logging

This commit is contained in:
Stephen Seo 2021-12-14 21:40:53 +09:00
parent ed7755d953
commit 4b8a5a65e1
2 changed files with 22 additions and 2 deletions

17
src/debug_log.rs Normal file
View file

@ -0,0 +1,17 @@
use std::fmt::Display;
#[cfg(debug_assertions)]
pub fn log<T>(msg: T) -> ()
where
T: Display,
{
println!("{}", msg);
}
#[cfg(not(debug_assertions))]
pub fn log<T>(msg: T) -> ()
where
T: Display,
{
// intentionally left blank, no logging in debug mode
}

View file

@ -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)),
}
});
}