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
65
66
use super::{MessageType, TaskId};
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LogMessage {
#[serde(rename = "type")]
pub typ: MessageType,
#[serde(skip_serializing_if = "Option::is_none")]
pub task: Option<TaskId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub origin_id: Option<String>,
pub message: String,
}
impl LogMessage {
pub fn new<S: Into<String>>(
typ: MessageType,
msg: S,
task: Option<TaskId>,
orid: Option<S>,
) -> Self {
Self {
typ,
task: task.map(Into::into),
origin_id: orid.map(Into::into),
message: msg.into(),
}
}
pub fn info<S: Into<String>>(msg: S, task: Option<TaskId>, orid: Option<S>) -> Self {
Self::new(MessageType::Info, msg, task, orid)
}
pub fn log<S: Into<String>>(msg: String, task: Option<TaskId>, orid: Option<String>) -> Self {
Self::new(MessageType::Log, msg, task, orid)
}
pub fn warn<S: Into<String>>(msg: S, task: Option<TaskId>, orid: Option<S>) -> Self {
Self::new(MessageType::Warning, msg, task, orid)
}
pub fn error<S: Into<String>>(msg: S, task: Option<TaskId>, orid: Option<S>) -> Self {
Self::new(MessageType::Error, msg, task, orid)
}
}