1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use processor::{OutputProcessor, ConfigurableFilter};

use std::collections::HashMap;
use std::sync::mpsc::Receiver;
use std::thread::JoinHandle;

/// # Stdout output
///
/// - sends output to stdout
///
/// ### catapult.conf
///
/// ```
/// output {
///   stdout
/// }
/// ```
/// ### Parameters
///
/// - none


pub struct Stdout {
  name: String
}

impl Stdout {
  pub fn new(name: String) -> Stdout {
    Stdout{ name: name }
  }
}

impl ConfigurableFilter for Stdout {
  fn human_name(&self) -> &str {
    self.name.as_ref()
  }

}

impl OutputProcessor for Stdout {
  fn start(&self, rx: Receiver<String>, config: &Option<HashMap<String,String>>) -> Result<JoinHandle<()>, String> {
    self.invoke(rx, config, Stdout::handle_func)
  }
  fn handle_func(rx: Receiver<String>, _config: Option<HashMap<String,String>>) {
      loop {
        match rx.recv() {
          Ok(l) => { println!("{}", l) }
          Err(e) => { panic!(e) }
        }
      }
  }
}