Skip to content

Commit

Permalink
Merge pull request #2 from gahag-cw/fix/invalid-json
Browse files Browse the repository at this point in the history
Don't emit invalid json on missing fields
  • Loading branch information
mladedav authored Dec 3, 2024
2 parents 4e296b5 + dbf2717 commit fcdb1fe
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/layer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|event, writer| {
event
.metadata()
.file()
.map_or(Ok(()), |file| write_escaped(writer, file))
match event.metadata().file() {
Some(file) => write_escaped(writer, file),
None => write!(writer, "null"),
}
})),
);
self
Expand All @@ -914,10 +914,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|event, writer| {
event
.metadata()
.line()
.map_or(Ok(()), |line| write!(writer, "{line}"))
match event.metadata().line() {
Some(line) => write!(writer, "{line}"),
None => write!(writer, "null"),
}
})),
);
self
Expand All @@ -942,9 +942,10 @@ where
self.keyed_values.insert(
SchemaKey::from(key.into()),
JsonValue::DynamicRawFromEvent(Box::new(|_event, writer| {
std::thread::current()
.name()
.map_or(Ok(()), |name| write_escaped(writer, name))
match std::thread::current().name() {
Some(name) => write_escaped(writer, name),
None => write!(writer, "null"),
}
})),
);
self
Expand Down

0 comments on commit fcdb1fe

Please sign in to comment.