Skip to main content

rivet_logger/processors/
tag.rs

1use crate::logger::{BoxError, LogRecord, LogValue, Processor};
2
3#[derive(Default)]
4pub struct Tag {
5    tags: Vec<String>,
6}
7
8impl Tag {
9    pub fn new(tags: Vec<String>) -> Self {
10        Self { tags }
11    }
12
13    pub fn add_tags(&mut self, tags: Vec<String>) -> &mut Self {
14        self.tags.extend(tags);
15        self
16    }
17
18    pub fn set_tags(&mut self, tags: Vec<String>) -> &mut Self {
19        self.tags = tags;
20        self
21    }
22}
23
24impl Processor for Tag {
25    fn process(&self, mut record: LogRecord) -> Result<LogRecord, BoxError> {
26        let values = self
27            .tags
28            .iter()
29            .cloned()
30            .map(LogValue::String)
31            .collect::<Vec<_>>();
32        record
33            .extra
34            .insert("tags".to_string(), LogValue::Array(values));
35        Ok(record)
36    }
37}