LogEntry: Tolerate null file, line, and function fields.
Change-Id: I555132fbcedd4a01923f3d0dcd0e90c22284e840
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
index 4c70e6f..2be17a2 100644
--- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/LogEntry.java
@@ -70,11 +70,21 @@
}
JsonObject json() {
- return Json.createObjectBuilder()
- .add("file", file)
- .add("line", line)
- .add("function", function)
- .build();
+ var b = Json.createObjectBuilder();
+
+ if (file != null) {
+ b.add("file", file);
+ }
+
+ if (line != null) {
+ b.add("line", line);
+ }
+
+ if (function != null) {
+ b.add("function", function);
+ }
+
+ return b.build();
}
}