From 5303673160fb8a52102a55774eb99dae1ebf5eda Mon Sep 17 00:00:00 2001 From: clecius Date: Mon, 8 Aug 2022 17:42:32 -0300 Subject: Quarkus: On/off toggle via configuration. Change-Id: I2b1b5796501784b4e21697fea85d5e1e12a3e12b --- .../runtime/GoogleCloudJsonLoggingRecorder.java | 7 +++++- .../jsonlogging/runtime/GoogleJsonLogConfig.java | 28 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java (limited to 'runtime/src/main/java') 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> initialize() { + public RuntimeValue> 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 -- cgit v1.2.3