summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclecius <clecius.martinkoski@gmail.com>2022-08-08 17:42:32 -0300
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-09-03 18:39:44 +0200
commit5303673160fb8a52102a55774eb99dae1ebf5eda (patch)
treec78b84d43934dd28689556a676731df46b653263
parentc567bf458883882e23cf642098e764c61d2ae094 (diff)
Quarkus: On/off toggle via configuration.
Change-Id: I2b1b5796501784b4e21697fea85d5e1e12a3e12b
-rw-r--r--deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java5
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingRecorder.java7
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java28
3 files changed, 37 insertions, 3 deletions
diff --git a/deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java b/deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java
index 7d4a93f..fdfcb1c 100644
--- a/deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java
+++ b/deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java
@@ -5,6 +5,7 @@
package eu.mulk.quarkus.googlecloud.jsonlogging.deployment;
import eu.mulk.quarkus.googlecloud.jsonlogging.runtime.GoogleCloudJsonLoggingRecorder;
+import eu.mulk.quarkus.googlecloud.jsonlogging.runtime.GoogleJsonLogConfig;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
@@ -38,7 +39,7 @@ public class GoogleCloudLoggingProcessor {
*/
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
- public LogConsoleFormatBuildItem setUpFormatter(GoogleCloudJsonLoggingRecorder recorder) {
- return new LogConsoleFormatBuildItem(recorder.initialize());
+ public LogConsoleFormatBuildItem setUpFormatter(GoogleCloudJsonLoggingRecorder recorder, GoogleJsonLogConfig config) {
+ return new LogConsoleFormatBuildItem(recorder.initialize(config));
}
}
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingRecorder.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingRecorder.java
index 7366a55..8bdb308 100644
--- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingRecorder.java
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingRecorder.java
@@ -10,6 +10,7 @@ import eu.mulk.quarkus.googlecloud.jsonlogging.StructuredParameterProvider;
import io.quarkus.arc.Arc;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
+
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -26,7 +27,10 @@ public class GoogleCloudJsonLoggingRecorder {
*
* @return the registered {@link Formatter}.
*/
- public RuntimeValue<Optional<java.util.logging.Formatter>> initialize() {
+ public RuntimeValue<Optional<java.util.logging.Formatter>> initialize(GoogleJsonLogConfig config) {
+ if(!config.jsonGoogle.enable) {
+ return new RuntimeValue<>(Optional.empty());
+ }
var parameterProviders =
Arc.container().select(StructuredParameterProvider.class).stream()
@@ -37,4 +41,5 @@ public class GoogleCloudJsonLoggingRecorder {
return new RuntimeValue<>(Optional.of(Formatter.load(parameterProviders, labelProviders)));
}
+
}
diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java
new file mode 100644
index 0000000..b73b0bc
--- /dev/null
+++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java
@@ -0,0 +1,28 @@
+package eu.mulk.quarkus.googlecloud.jsonlogging.runtime;
+
+import io.quarkus.runtime.annotations.*;
+
+/**
+ * Configuration for Google JSON log formatting.
+ */
+@ConfigRoot(phase = ConfigPhase.RUN_TIME, name = "log.console")
+public class GoogleJsonLogConfig {
+
+ /**
+ * Console google json logging.
+ */
+ @ConfigDocSection
+ @ConfigItem(name = "json.google")
+ JsonConfig jsonGoogle;
+
+ @ConfigGroup
+ public static class JsonConfig {
+
+ /**
+ * Determine whether to enable the JSON console formatting extension, which disables "normal" console formatting.
+ */
+ @ConfigItem(name = ConfigItem.PARENT, defaultValue = "true")
+ boolean enable;
+
+ }
+} \ No newline at end of file