]> git.seodisparate.com - mpd_info_screen/commitdiff
WIP add debug logging
authorStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 12:40:53 +0000 (21:40 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 14 Dec 2021 12:40:53 +0000 (21:40 +0900)
src/debug_log.rs [new file with mode: 0644]
src/main.rs

diff --git a/src/debug_log.rs b/src/debug_log.rs
new file mode 100644 (file)
index 0000000..4f8cd5c
--- /dev/null
@@ -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
+}
index 9ceace9cbfae3fb8bed130f3a784bda3201334bc..eb84537185901f6260a5864e82f40a6f3d26aeea 100644 (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)),
         }
     });
 }