From 5b6e06928bbd5466d0c65149e8c7e44871e71a8c Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Tue, 21 Mar 2023 23:09:15 +0100 Subject: =?UTF-8?q?=F0=9F=93=96=20Add=20logging=20and=20term=20writes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit println works for a while. Was time to set up something better. Worth to not that there is a big difference between logging and writing to the terminal which is why both slog and console was dragged in. Might seem similar but purpose is not the same. Most of the time the log is interesting during runtime but user messages does not belong in the log. --- racer-tracer/src/key_inputs.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'racer-tracer/src/key_inputs.rs') diff --git a/racer-tracer/src/key_inputs.rs b/racer-tracer/src/key_inputs.rs index 06e0f99..1e3505e 100644 --- a/racer-tracer/src/key_inputs.rs +++ b/racer-tracer/src/key_inputs.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use minifb::{Key, Window}; +use slog::Logger; use crate::error::TracerError; @@ -9,13 +10,15 @@ pub type KeyClosure<'a> = &'a (dyn Fn(f64) -> Result<(), TracerError> + Send + S pub struct KeyInputs<'a> { is_down_callbacks: HashMap>>, is_released_callbacks: HashMap>>, + log: Logger, } impl<'a> KeyInputs<'a> { - pub fn new() -> Self { + pub fn new(log: Logger) -> Self { KeyInputs { is_down_callbacks: HashMap::new(), is_released_callbacks: HashMap::new(), + log, } } @@ -39,7 +42,7 @@ impl<'a> KeyInputs<'a> { .for_each(|(_key, callbacks)| { callbacks.iter_mut().for_each(|callback| { if let Err(e) = callback(dt) { - println!("Key callback error: {}", e) + error!(self.log, "Key callback error: {}", e); } }) }); @@ -49,7 +52,7 @@ impl<'a> KeyInputs<'a> { .for_each(|(_key, callbacks)| { callbacks.iter_mut().for_each(|callback| { if let Err(e) = callback(dt) { - println!("Key callback error: {}", e) + error!(self.log, "Key callback error: {}", e); } }) }); -- cgit v1.2.3