From fa7277098608102b246cd73821938b77181ee8b8 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Thu, 23 Mar 2023 16:53:01 -0600 Subject: [PATCH] $DEBUG to see output in stderr --- src/config.rs | 3 +++ src/stream.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index 88161e7..39fe31e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,6 +18,7 @@ pub struct Streams { pub struct Stream { pub engine: Engine, pub format: Option, + pub debug: bool, } #[derive(Serialize, Deserialize, Debug)] @@ -83,6 +84,7 @@ fn build_config_std() -> Config { return Config { streams: Streams{ input: Stream { + debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true", format: match env::var("INPUT_FORMAT") { Ok(x) => Some(x), Err(_) => None, @@ -110,6 +112,7 @@ fn build_config_std() -> Config { }, }, output: Stream { + debug: env::var("DEBUG").unwrap_or(String::from("false")) == "true", format: match env::var("OUTPUT_FORMAT") { Ok(x) => Some(x), Err(_) => None, diff --git a/src/stream.rs b/src/stream.rs index 7580da7..bfee73e 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -201,21 +201,27 @@ pub fn build_output_stream(cfg: &Stream) -> Box { pub struct OutputStreamFormatted { format: Option, stream: Box, + debug: bool, } pub fn build_formatted_output_stream(cfg: &Stream, stream: Box) -> Box { return Box::new(OutputStreamFormatted{ format: cfg.format.clone(), + debug: cfg.debug, stream: stream, }); } impl OutputStream for OutputStreamFormatted { fn put(&mut self, v: Vec) { - match self.format.as_ref() { - Some(x) => self.stream.put(sprintf(x, v)), - None => self.stream.put(v), + let v2 = match self.format.as_ref() { + Some(x) => sprintf(x, v), + None => v, }; + if self.debug { + eprintln!("output: {}", v2.iter().collect::()); + } + self.stream.put(v2); } }