in src/flowgger/encoder/ltsv_encoder.rs [66:124]
fn encode(&self, record: Record) -> Result<Vec<u8>, &'static str> {
let mut res = LTSVString::new();
if let Some(sd_vec) = record.sd {
for &ref sd in &sd_vec {
// Warning: LTSV doesn't have a concept of structued data. In case there are
// several, all their attributes will be aded as fields. So if several structured
// data have the same key, only the last value will show as it will overwrite the
// others. We could use the sd_id to prefix the field to sove this but this is a
// breaking change.
for &(ref name, ref value) in &sd.pairs {
let name = if (*name).starts_with('_') {
&name[1..] as &str
} else {
name as &str
};
match *value {
SDValue::String(ref value) => res.insert(name, value),
SDValue::Bool(ref value) => res.insert(name, &value.to_string()),
SDValue::F64(ref value) => res.insert(name, &value.to_string()),
SDValue::I64(ref value) => res.insert(name, &value.to_string()),
SDValue::U64(ref value) => res.insert(name, &value.to_string()),
SDValue::Null => res.insert(name, ""),
}
}
}
}
for &(ref name, ref value) in &self.extra {
let name = if (*name).starts_with('_') {
&name[1..] as &str
} else {
name as &str
};
res.insert(name, value);
}
res.insert("host", &record.hostname);
res.insert("time", &record.ts.to_string());
if let Some(msg) = record.msg {
res.insert("message", &msg);
}
if let Some(full_msg) = record.full_msg {
res.insert("full_message", &full_msg);
}
if let Some(severity) = record.severity {
res.insert("level", &format!("{}", severity));
}
if let Some(facility) = record.facility {
res.insert("facility", &format!("{}", facility));
}
if let Some(appname) = record.appname {
res.insert("appname", &appname);
}
if let Some(procid) = record.procid {
res.insert("procid", &procid);
}
if let Some(msgid) = record.msgid {
res.insert("msgid", &msgid);
}
Ok(res.finalize().into_bytes())
}