1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[derive(Debug, Serialize, Deserialize)]
pub enum Priority {
Emergency,
Alert,
Critical,
Error,
Warning,
Notice,
Informational,
Debug,
Trace,
None,
}
impl Display for Priority {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Emergency => write!(f, "Emergency"),
Self::Alert => write!(f, "Alert"),
Self::Critical => write!(f, "Critical"),
Self::Error => write!(f, "Error"),
Self::Warning => write!(f, "Warning"),
Self::Notice => write!(f, "Notice"),
Self::Informational => write!(f, "Informational"),
Self::Debug => write!(f, "Debug"),
Self::Trace => write!(f, "Trace"),
Self::None => write!(f, "None"),
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Log {
pub timestamp: DateTime<Utc>,
pub priority: Priority,
pub message: String,
}
impl Log {
pub fn new(priority: Priority, message: impl Into<String>) -> Self {
Self {
timestamp: Utc::now(),
priority,
message: message.into(),
}
}
}
#[derive(Serialize)]
pub struct LogRequest<'a> {
pub logs: &'a [Log],
}
impl<'a> LogRequest<'a> {
pub fn new(logs: &'a [Log]) -> Self {
Self { logs }
}
}