summaryrefslogtreecommitdiff
path: root/runtime/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/main')
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java15
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java6
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ParameterProvider.java12
3 files changed, 32 insertions, 1 deletions
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
index d2e5562..c6e177c 100644
--- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/Formatter.java
@@ -3,6 +3,7 @@ package eu.mulk.quarkus.googlecloud.jsonlogging;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -28,12 +29,26 @@ public class Formatter extends ExtFormatter {
private static final String ERROR_EVENT_TYPE =
"type.googleapis.com/google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent";
+ private final List<ParameterProvider> parameterProviders;
+
+ public Formatter(Collection<ParameterProvider> parameterProviders) {
+ this.parameterProviders = List.copyOf(parameterProviders);
+ }
+
@Override
public String format(ExtLogRecord logRecord) {
var message = formatMessageWithStackTrace(logRecord);
List<StructuredParameter> parameters = new ArrayList<>();
Map<String, String> labels = new HashMap<>();
+
+ for (var parameterProvider : parameterProviders) {
+ var parameter = parameterProvider.get();
+ if (parameter != null) {
+ parameters.add(parameter);
+ }
+ }
+
if (logRecord.getParameters() != null) {
for (var parameter : logRecord.getParameters()) {
if (parameter instanceof StructuredParameter) {
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java
index db2c2e9..ace4a28 100644
--- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/GoogleCloudJsonLoggingRecorder.java
@@ -1,12 +1,16 @@
package eu.mulk.quarkus.googlecloud.jsonlogging;
+import io.quarkus.arc.Arc;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import java.util.Optional;
+import java.util.stream.Collectors;
@Recorder
public class GoogleCloudJsonLoggingRecorder {
public RuntimeValue<Optional<java.util.logging.Formatter>> initialize() {
- return new RuntimeValue<>(Optional.of(new Formatter()));
+ var parameterProviders =
+ Arc.container().select(ParameterProvider.class).stream().collect(Collectors.toList());
+ return new RuntimeValue<>(Optional.of(new Formatter(parameterProviders)));
}
}
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ParameterProvider.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ParameterProvider.java
new file mode 100644
index 0000000..fb212a3
--- /dev/null
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/ParameterProvider.java
@@ -0,0 +1,12 @@
+package eu.mulk.quarkus.googlecloud.jsonlogging;
+
+/**
+ * A user-supplied provider for {@link StructuredParameter}s.
+ *
+ * <p>Any CDI beans registered under this class are applied to each log entry that is logged.
+ */
+public interface ParameterProvider {
+
+ /** Provides a {@link StructuredParameter} to add to each log entry that is logged. */
+ StructuredParameter get();
+}