use serde::Serialize;
#[derive(Serialize)]
pub(crate) struct Schema<T: Serialize> {
pub log_level: String,
pub msg: T,
pub tag: Option<String>,
}
pub(crate) struct SchemaBuilder<T: Serialize> {
log_level: Option<String>,
msg: Option<T>,
tag: Option<String>,
}
impl<T: Serialize> SchemaBuilder<T> {
pub fn new() -> Self {
Self {
log_level: None,
msg: None,
tag: None,
}
}
pub fn log_level(mut self, log_level: String) -> Self {
self.log_level = Some(log_level);
self
}
pub fn msg(mut self, msg: T) -> Self {
self.msg = Some(msg);
self
}
pub fn tag(mut self, tag: String) -> Self {
self.tag = Some(tag);
self
}
pub fn build(self) -> Schema<T> {
Schema {
log_level: self.log_level.expect("Log level must be set!"),
msg: self.msg.expect("Msg must be set!"),
tag: self.tag,
}
}
}