From 090b885b7d6dc82e5ec066dbf81d071086e9ec10 Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 3 Sep 2022 18:23:23 +0200 Subject: Quarkus: Simplify and document on/off toggle. Change-Id: I90b5879ff99ec54deb17453af709ce2ba7070c0d --- README.adoc | 8 +++++++ .../deployment/GoogleCloudLoggingProcessor.java | 7 +++--- examples/quarkus/pom.xml | 2 +- .../src/main/resources/application.properties | 4 +++- .../GoogleCloudJsonLoggingConfiguration.java | 22 +++++++++++++++++ .../runtime/GoogleCloudJsonLoggingRecorder.java | 7 +++--- .../jsonlogging/runtime/GoogleJsonLogConfig.java | 28 ---------------------- 7 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingConfiguration.java delete mode 100644 runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java diff --git a/README.adoc b/README.adoc index 27d8cf8..3460598 100644 --- a/README.adoc +++ b/README.adoc @@ -63,6 +63,14 @@ dependencies { } ---- +By default the extension is turned on. You can turn the extension on +or off explicitly by configuring the `quarkus.log.console.google` key +in `application.properties`: + +[source,properties] +---- +quarkus.log.console.google = true +---- == Activation (Other Frameworks) 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 fdfcb1c..8ef0962 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 @@ -4,8 +4,8 @@ package eu.mulk.quarkus.googlecloud.jsonlogging.deployment; +import eu.mulk.quarkus.googlecloud.jsonlogging.runtime.GoogleCloudJsonLoggingConfiguration; 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; @@ -39,7 +39,8 @@ public class GoogleCloudLoggingProcessor { */ @BuildStep @Record(ExecutionTime.RUNTIME_INIT) - public LogConsoleFormatBuildItem setUpFormatter(GoogleCloudJsonLoggingRecorder recorder, GoogleJsonLogConfig config) { - return new LogConsoleFormatBuildItem(recorder.initialize(config)); + public LogConsoleFormatBuildItem setUpFormatter( + GoogleCloudJsonLoggingRecorder recorder, GoogleCloudJsonLoggingConfiguration configuration) { + return new LogConsoleFormatBuildItem(recorder.initialize(configuration)); } } diff --git a/examples/quarkus/pom.xml b/examples/quarkus/pom.xml index 2eeeb40..6e4f042 100644 --- a/examples/quarkus/pom.xml +++ b/examples/quarkus/pom.xml @@ -14,7 +14,7 @@ SPDX-License-Identifier: GPL-3.0-or-later eu.mulk.quarkus-googlecloud-jsonlogging quarkus-googlecloud-jsonlogging-parent - 4.0.0 + 5.0.0 quarkus-googlecloud-jsonlogging-quarkus-example diff --git a/examples/quarkus/src/main/resources/application.properties b/examples/quarkus/src/main/resources/application.properties index 8b991a7..24eae27 100644 --- a/examples/quarkus/src/main/resources/application.properties +++ b/examples/quarkus/src/main/resources/application.properties @@ -1,3 +1,5 @@ # SPDX-FileCopyrightText: © 2021 Matthias Andreas Benkard # -# SPDX-License-Identifier: GPL-3.0-or-later \ No newline at end of file +# SPDX-License-Identifier: GPL-3.0-or-later + +quarkus.log.console.google = true diff --git a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingConfiguration.java b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingConfiguration.java new file mode 100644 index 0000000..21a4ca9 --- /dev/null +++ b/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingConfiguration.java @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: © 2022 Matthias Andreas Benkard +// +// SPDX-License-Identifier: LGPL-3.0-or-later + +package eu.mulk.quarkus.googlecloud.jsonlogging.runtime; + +import io.quarkus.runtime.annotations.ConfigItem; +import io.quarkus.runtime.annotations.ConfigPhase; +import io.quarkus.runtime.annotations.ConfigRoot; + +/** Configuration for console logging in Google Cloud Logging JSON format. */ +@ConfigRoot(prefix = "quarkus.log.console", name = "google", phase = ConfigPhase.RUN_TIME) +public class GoogleCloudJsonLoggingConfiguration { + + /** + * Whether to enable Google Cloud Logging JSON logging to stdout/stderr. + * + *

Replaces the regular plain-text format for console logs. + */ + @ConfigItem(defaultValue = "true", name = ConfigItem.PARENT) + public boolean enabled; +} 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 8bdb308..af09231 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,7 +10,6 @@ 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; @@ -27,8 +26,9 @@ public class GoogleCloudJsonLoggingRecorder { * * @return the registered {@link Formatter}. */ - public RuntimeValue> initialize(GoogleJsonLogConfig config) { - if(!config.jsonGoogle.enable) { + public RuntimeValue> initialize( + GoogleCloudJsonLoggingConfiguration configuration) { + if (!configuration.enabled) { return new RuntimeValue<>(Optional.empty()); } @@ -41,5 +41,4 @@ 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 deleted file mode 100644 index b73b0bc..0000000 --- a/runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleJsonLogConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -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