saluki_core/data_model/event/log/
mod.rs1use std::collections::HashMap;
4
5use serde_json::Value as JsonValue;
6use stringtheory::MetaString;
7
8use crate::data_model::tags::TagSet;
9
10#[derive(Clone, Debug, PartialEq)]
12pub struct Log {
13 message: MetaString,
15 status: Option<LogStatus>,
17 source: Option<MetaString>,
19 hostname: MetaString,
21 service: MetaString,
23 tags: TagSet,
25 additional_properties: HashMap<MetaString, JsonValue>,
27}
28
29#[derive(Clone, Copy, Debug, PartialEq)]
31pub enum LogStatus {
32 Trace,
34 Emergency,
36 Alert,
38 Fatal,
40 Error,
42 Warning,
44 Notice,
46 Info,
48 Debug,
50}
51
52impl LogStatus {
53 pub fn as_str(&self) -> &str {
55 match self {
56 LogStatus::Trace => "Trace",
57 LogStatus::Emergency => "Emergency",
58 LogStatus::Alert => "Alert",
59 LogStatus::Fatal => "Fatal",
60 LogStatus::Error => "Error",
61 LogStatus::Warning => "Warning",
62 LogStatus::Notice => "Notice",
63 LogStatus::Info => "Info",
64 LogStatus::Debug => "Debug",
65 }
66 }
67}
68
69impl Log {
70 pub fn new(message: impl Into<MetaString>) -> Self {
72 Self {
73 message: message.into(),
74 status: None,
75 source: None,
76 hostname: MetaString::empty(),
77 service: MetaString::empty(),
78 tags: TagSet::default(),
79 additional_properties: HashMap::new(),
80 }
81 }
82
83 pub fn with_status(mut self, status: impl Into<Option<LogStatus>>) -> Self {
85 self.status = status.into();
86 self
87 }
88
89 pub fn with_source(mut self, source: impl Into<Option<MetaString>>) -> Self {
91 self.source = source.into();
92 self
93 }
94
95 pub fn with_hostname(mut self, hostname: impl Into<Option<MetaString>>) -> Self {
97 self.hostname = hostname.into().unwrap_or_else(MetaString::empty);
98 self
99 }
100
101 pub fn with_service(mut self, service: impl Into<Option<MetaString>>) -> Self {
103 self.service = service.into().unwrap_or_else(MetaString::empty);
104 self
105 }
106
107 pub fn with_tags(mut self, tags: impl Into<Option<TagSet>>) -> Self {
109 self.tags = tags.into().unwrap_or_else(TagSet::default);
110 self
111 }
112
113 pub fn with_additional_properties(
115 mut self, additional_properties: impl Into<Option<HashMap<MetaString, JsonValue>>>,
116 ) -> Self {
117 self.additional_properties = additional_properties.into().unwrap_or_default();
118 self
119 }
120
121 pub fn message(&self) -> &str {
123 &self.message
124 }
125
126 pub fn status(&self) -> Option<LogStatus> {
128 self.status
129 }
130
131 pub fn source(&self) -> &Option<MetaString> {
133 &self.source
134 }
135
136 pub fn hostname(&self) -> &str {
138 &self.hostname
139 }
140
141 pub fn service(&self) -> &str {
143 &self.service
144 }
145
146 pub fn tags(&self) -> &TagSet {
148 &self.tags
149 }
150
151 pub fn additional_properties(&self) -> &HashMap<MetaString, JsonValue> {
153 &self.additional_properties
154 }
155}