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
mod builder;
mod sink;

pub use builder::*;
pub use sink::*;

/// Process log lines with [`Self::transformer`]
/// and write them to [`Self::sink`].
/// To create this, use [`ProcessorBuilder::sink`].
pub struct Processor {
  /// See [`ProcessorBuilder::transformer`].
  transformer: Box<dyn FnMut(String) -> Option<String> + Send>,
  /// See [`ProcessorBuilder::sink`].
  sink: Sink,
}

impl Processor {
  /// Process a log line with [`Self::transformer`] and write it to [`Self::sink`].
  pub async fn process(&mut self, line: String) {
    if let Some(transformed) = (self.transformer)(line) {
      self.sink.write_line(transformed).await;
    }
  }

  /// Flush [`Self::sink`].
  pub async fn flush(&mut self) {
    self.sink.flush().await;
  }
}