summaryrefslogtreecommitdiff
path: root/racer-tracer/src/image_action
diff options
context:
space:
mode:
authorSakarias Johansson <sakarias.johansson@goodbyekansas.com>2023-03-21 23:09:15 +0100
committerSakarias Johansson <sakariasjohansson@hotmail.com>2023-04-05 19:38:04 +0200
commit5b6e06928bbd5466d0c65149e8c7e44871e71a8c (patch)
tree7165d767e67b99404e9b382a2494f46d4a6ea35f /racer-tracer/src/image_action
parented8de4988d3f1c81bc4ca833c760dce1497e99d7 (diff)
downloadracer-tracer-5b6e06928bbd5466d0c65149e8c7e44871e71a8c.tar.gz
racer-tracer-5b6e06928bbd5466d0c65149e8c7e44871e71a8c.tar.xz
racer-tracer-5b6e06928bbd5466d0c65149e8c7e44871e71a8c.zip
📖 Add logging and term writes
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.
Diffstat (limited to 'racer-tracer/src/image_action')
-rw-r--r--racer-tracer/src/image_action/png.rs9
-rw-r--r--racer-tracer/src/image_action/wait_for_signal.rs11
2 files changed, 15 insertions, 5 deletions
diff --git a/racer-tracer/src/image_action/png.rs b/racer-tracer/src/image_action/png.rs
index 4887d3d..dbed285 100644
--- a/racer-tracer/src/image_action/png.rs
+++ b/racer-tracer/src/image_action/png.rs
@@ -1,9 +1,10 @@
use std::{path::PathBuf, sync::RwLock};
use sha2::{Digest, Sha256};
+use slog::Logger;
use synchronoise::SignalEvent;
-use crate::{config::Config, error::TracerError};
+use crate::{config::Config, error::TracerError, terminal::Terminal};
use super::ImageAction;
@@ -15,6 +16,8 @@ impl ImageAction for SavePng {
screen_buffer: &RwLock<Vec<u32>>,
event: &SignalEvent,
config: &Config,
+ log: Logger,
+ _term: &Terminal,
) -> Result<(), TracerError> {
let status = event.status();
event.reset();
@@ -40,7 +43,7 @@ impl ImageAction for SavePng {
})
.and_then(|buf| match &config.image_output_dir {
Some(image_dir) => {
- println!("Saving image...");
+ info!(log, "Saving image...");
let mut sha = Sha256::new();
sha.update(buf.as_slice());
@@ -60,7 +63,7 @@ impl ImageAction for SavePng {
TracerError::ImageSave(error)
})
.map(|_| {
- println!("Saved image to: {}", file_path.to_string_lossy());
+ info!(log, "Saved image to: {}", file_path.to_string_lossy());
})
}
None => Ok(()),
diff --git a/racer-tracer/src/image_action/wait_for_signal.rs b/racer-tracer/src/image_action/wait_for_signal.rs
index 54480ac..0ffe5e7 100644
--- a/racer-tracer/src/image_action/wait_for_signal.rs
+++ b/racer-tracer/src/image_action/wait_for_signal.rs
@@ -1,8 +1,13 @@
use std::sync::RwLock;
+use slog::Logger;
use synchronoise::SignalEvent;
-use crate::{config::Config, error::TracerError};
+use crate::{
+ config::Config,
+ error::TracerError,
+ terminal::{write_term, Terminal},
+};
use super::ImageAction;
@@ -14,9 +19,11 @@ impl ImageAction for WaitForSignal {
_screen_buffer: &RwLock<Vec<u32>>,
event: &SignalEvent,
_config: &Config,
+ _log: Logger,
+ term: &Terminal,
) -> Result<(), TracerError> {
if !event.status() {
- println!("Press R to resume.");
+ write_term!(term, "Press R to resume.");
event.wait();
}
event.reset();