saluki_core/data_model/event/log/
mod.rs1use std::collections::HashMap;
4
5use saluki_context::tags::SharedTagSet;
6use serde_json::Value as JsonValue;
7use stringtheory::MetaString;
8
9#[derive(Clone, Debug, PartialEq)]
11pub struct Log {
12 message: MetaString,
14 status: Option<LogStatus>,
16 source: Option<MetaString>,
18 hostname: MetaString,
20 service: MetaString,
22 tags: SharedTagSet,
24 additional_properties: HashMap<MetaString, JsonValue>,
26}
27
28#[derive(Clone, Copy, Debug, PartialEq)]
30pub enum LogStatus {
31 Trace,
33 Emergency,
35 Alert,
37 Fatal,
39 Error,
41 Warning,
43 Notice,
45 Info,
47 Debug,
49}
50
51impl LogStatus {
52 pub fn as_str(&self) -> &str {
54 match self {
55 LogStatus::Trace => "Trace",
56 LogStatus::Emergency => "Emergency",
57 LogStatus::Alert => "Alert",
58 LogStatus::Fatal => "Fatal",
59 LogStatus::Error => "Error",
60 LogStatus::Warning => "Warning",
61 LogStatus::Notice => "Notice",
62 LogStatus::Info => "Info",
63 LogStatus::Debug => "Debug",
64 }
65 }
66}
67
68impl Log {
69 pub fn new(message: impl Into<MetaString>) -> Self {
71 Self {
72 message: message.into(),
73 status: None,
74 source: None,
75 hostname: MetaString::empty(),
76 service: MetaString::empty(),
77 tags: SharedTagSet::default(),
78 additional_properties: HashMap::new(),
79 }
80 }
81
82 pub fn with_status(mut self, status: impl Into<Option<LogStatus>>) -> Self {
84 self.status = status.into();
85 self
86 }
87
88 pub fn with_source(mut self, source: impl Into<Option<MetaString>>) -> Self {
90 self.source = source.into();
91 self
92 }
93
94 pub fn with_hostname(mut self, hostname: impl Into<Option<MetaString>>) -> Self {
96 self.hostname = hostname.into().unwrap_or_else(MetaString::empty);
97 self
98 }
99
100 pub fn with_service(mut self, service: impl Into<Option<MetaString>>) -> Self {
102 self.service = service.into().unwrap_or_else(MetaString::empty);
103 self
104 }
105
106 pub fn with_tags(mut self, tags: impl Into<Option<SharedTagSet>>) -> Self {
108 self.tags = tags.into().unwrap_or_else(SharedTagSet::default);
109 self
110 }
111
112 pub fn with_additional_properties(
114 mut self, additional_properties: impl Into<Option<HashMap<MetaString, JsonValue>>>,
115 ) -> Self {
116 self.additional_properties = additional_properties.into().unwrap_or_default();
117 self
118 }
119
120 pub fn message(&self) -> &str {
122 &self.message
123 }
124
125 pub fn status(&self) -> Option<LogStatus> {
127 self.status
128 }
129
130 pub fn source(&self) -> &Option<MetaString> {
132 &self.source
133 }
134
135 pub fn hostname(&self) -> &str {
137 &self.hostname
138 }
139
140 pub fn service(&self) -> &str {
142 &self.service
143 }
144
145 pub fn tags(&self) -> &SharedTagSet {
147 &self.tags
148 }
149
150 pub fn additional_properties(&self) -> &HashMap<MetaString, JsonValue> {
152 &self.additional_properties
153 }
154}