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
use crate::tracers::tracer::Tracer;
use derive_more::{Deref, DerefMut};
use rill_protocol::flow::meta::alert::{AlertEvent, AlertState};
use rill_protocol::io::provider::Path;

/// This tracer sends text messages.
#[derive(Debug, Deref, DerefMut, Clone)]
pub struct AlertTracer {
    tracer: Tracer<AlertState>,
}

impl AlertTracer {
    /// Create a new instance of the `Tracer`.
    pub fn new(path: Path) -> Self {
        let state = AlertState::new();
        // TODO: Use the `Receiver`
        let tracer = Tracer::new_push(state, path).0;
        Self { tracer }
    }

    /// Writes a message.
    pub fn alert(&self, message: String) {
        let data = AlertEvent { msg: message };
        self.tracer.send(data, None);
    }
}