saluki_core/data_model/event/log/
mod.rs1use std::collections::HashMap;
4use std::num::NonZeroU64;
5
6use serde_json::Value as JsonValue;
7use stringtheory::MetaString;
8
9use crate::data_model::tags::TagSet;
10
11#[derive(Clone, Debug, PartialEq)]
13pub struct Log {
14 message: MetaString,
16 ingestion_timestamp: Option<NonZeroU64>,
18 status: MetaString,
22 source: Option<MetaString>,
24 hostname: MetaString,
26 service: MetaString,
28 tags: TagSet,
30 additional_properties: HashMap<MetaString, JsonValue>,
32}
33
34impl Log {
35 pub fn new(message: impl Into<MetaString>) -> Self {
37 Self {
38 message: message.into(),
39 ingestion_timestamp: None,
40 status: MetaString::empty(),
41 source: None,
42 hostname: MetaString::empty(),
43 service: MetaString::empty(),
44 tags: TagSet::default(),
45 additional_properties: HashMap::new(),
46 }
47 }
48
49 pub fn with_message(mut self, message: impl Into<MetaString>) -> Self {
51 self.message = message.into();
52 self
53 }
54
55 pub fn with_ingestion_timestamp(mut self, timestamp_ns: u64) -> Self {
60 self.ingestion_timestamp = NonZeroU64::new(timestamp_ns);
61 self
62 }
63
64 pub fn with_status(mut self, status: impl Into<MetaString>) -> Self {
68 self.status = status.into();
69 self
70 }
71
72 pub fn with_source(mut self, source: impl Into<Option<MetaString>>) -> Self {
74 self.source = source.into();
75 self
76 }
77
78 pub fn with_hostname(mut self, hostname: impl Into<Option<MetaString>>) -> Self {
80 self.hostname = hostname.into().unwrap_or_else(MetaString::empty);
81 self
82 }
83
84 pub fn with_service(mut self, service: impl Into<Option<MetaString>>) -> Self {
86 self.service = service.into().unwrap_or_else(MetaString::empty);
87 self
88 }
89
90 pub fn with_tags(mut self, tags: impl Into<Option<TagSet>>) -> Self {
92 self.tags = tags.into().unwrap_or_else(TagSet::default);
93 self
94 }
95
96 pub fn with_additional_properties(
98 mut self, additional_properties: impl Into<Option<HashMap<MetaString, JsonValue>>>,
99 ) -> Self {
100 self.additional_properties = additional_properties.into().unwrap_or_default();
101 self
102 }
103
104 pub fn message(&self) -> &str {
106 &self.message
107 }
108
109 pub fn ingestion_timestamp(&self) -> Option<u64> {
111 self.ingestion_timestamp.map(NonZeroU64::get)
112 }
113
114 pub fn status(&self) -> &str {
116 &self.status
117 }
118
119 pub fn source(&self) -> &Option<MetaString> {
121 &self.source
122 }
123
124 pub fn hostname(&self) -> &str {
126 &self.hostname
127 }
128
129 pub fn service(&self) -> &str {
131 &self.service
132 }
133
134 pub fn tags(&self) -> &TagSet {
136 &self.tags
137 }
138
139 pub fn additional_properties(&self) -> &HashMap<MetaString, JsonValue> {
141 &self.additional_properties
142 }
143}