summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-09-03 18:23:23 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2022-09-03 18:43:36 +0200
commit090b885b7d6dc82e5ec066dbf81d071086e9ec10 (patch)
tree3203c963cba5842a9f78af0e61e16697b14e9bd7
parent5303673160fb8a52102a55774eb99dae1ebf5eda (diff)
Quarkus: Simplify and document on/off toggle.
Change-Id: I90b5879ff99ec54deb17453af709ce2ba7070c0d
-rw-r--r--README.adoc8
-rw-r--r--deployment/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/deployment/GoogleCloudLoggingProcessor.java7
-rw-r--r--examples/quarkus/pom.xml2
-rw-r--r--examples/quarkus/src/main/resources/application.properties4
-rw-r--r--runtime/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/runtime/GoogleCloudJsonLoggingConfiguration.java22
-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
7 files changed, 41 insertions, 37 deletions
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
<parent>
<groupId>eu.mulk.quarkus-googlecloud-jsonlogging</groupId>
<artifactId>quarkus-googlecloud-jsonlogging-parent</artifactId>
- <version>4.0.0</version>
+ <version>5.0.0</version>
</parent>
<artifactId>quarkus-googlecloud-jsonlogging-quarkus-example</artifactId>
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 <code@mail.matthias.benkard.de>
#
-# 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 <code@mail.matthias.benkard.de>
+//
+// 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 <code>stdout</code>/<code>stderr</code>.
+ *
+ * <p>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<Optional<java.util.logging.Formatter>> initialize(GoogleJsonLogConfig config) {
- if(!config.jsonGoogle.enable) {
+ public RuntimeValue<Optional<java.util.logging.Formatter>> 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