Skip to main content

truefix_log/
composite.rs

1//! Fan-out log.
2
3use crate::Log;
4
5/// Fans every entry out to each wrapped log.
6pub struct CompositeLog {
7    logs: Vec<Box<dyn Log>>,
8}
9
10impl CompositeLog {
11    /// Create a composite over `logs`.
12    pub fn new(logs: Vec<Box<dyn Log>>) -> Self {
13        Self { logs }
14    }
15}
16
17#[async_trait::async_trait]
18impl Log for CompositeLog {
19    fn on_incoming(&self, message: &str) {
20        for log in &self.logs {
21            log.on_incoming(message);
22        }
23    }
24    fn on_outgoing(&self, message: &str) {
25        for log in &self.logs {
26            log.on_outgoing(message);
27        }
28    }
29    fn on_event(&self, text: &str) {
30        for log in &self.logs {
31            log.on_event(text);
32        }
33    }
34    async fn shutdown(&self) {
35        for log in &self.logs {
36            log.shutdown().await;
37        }
38    }
39}