summaryrefslogtreecommitdiff
path: root/core/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-09-24 12:57:37 +0200
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-09-24 13:48:17 +0200
commitddcce2e8bc1c43e73a4033b4d76b5e06a4a3ad89 (patch)
treec2f8f53ec1dc0480c8dcc895605f5e961989d626 /core/src/main/java/eu
parent95c2a90fb4d0a8c69af70f12dd12cdb168116cb4 (diff)
feat(core): Add DefaultConfiguratorFactory for JBoss Log Manager 3.x.
Change-Id: I6bf88c9e6c8c4aba303cc1d18e8f18c917dd6b88
Diffstat (limited to 'core/src/main/java/eu')
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultConfiguratorFactory.java65
-rw-r--r--core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultEmbeddedConfigurator.java4
2 files changed, 67 insertions, 2 deletions
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultConfiguratorFactory.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultConfiguratorFactory.java
new file mode 100644
index 0000000..2ac5587
--- /dev/null
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultConfiguratorFactory.java
@@ -0,0 +1,65 @@
+// SPDX-FileCopyrightText: © 2023 Matthias Andreas Benkard <code@mail.matthias.benkard.de>
+//
+// SPDX-License-Identifier: LGPL-3.0-or-later
+
+package eu.mulk.quarkus.googlecloud.jsonlogging.logmanager;
+
+import eu.mulk.quarkus.googlecloud.jsonlogging.Formatter;
+import java.io.InputStream;
+import java.util.logging.Handler;
+import org.jboss.logmanager.ConfiguratorFactory;
+import org.jboss.logmanager.LogContext;
+import org.jboss.logmanager.LogContextConfigurator;
+import org.jboss.logmanager.handlers.ConsoleHandler;
+
+/**
+ * A convenient {@link ConfiguratorFactory} for JBoss Log Manager.
+ *
+ * <p>You can register this class through the {@link java.util.ServiceLoader} mechanism as a
+ * provider of the {@link ConfiguratorFactory} interface (under the name of {@code
+ * org.jboss.logmanager.ConfiguratorFactory}) to automatically register a {@link ConsoleHandler}
+ * using {@link Formatter} as the default log output method for the application.
+ */
+public final class DefaultConfiguratorFactory implements ConfiguratorFactory {
+
+ private final Handler[] rootHandlers;
+ private final ConfiguratorFactory upstreamConfiguratorFactory;
+
+ /**
+ * Constructs a JBoss Log Manager configuration that uses {@link Formatter} and {@link
+ * ConsoleHandler} for log output.
+ */
+ @SuppressWarnings({"java:S2095", "resource"})
+ public DefaultConfiguratorFactory() {
+ rootHandlers = new Handler[] {createConsoleHandler()};
+ upstreamConfiguratorFactory =
+ new org.jboss.logmanager.configuration.DefaultConfiguratorFactory();
+ }
+
+ /**
+ * Creates a {@link ConsoleHandler} that uses {@link Formatter} for formatting.
+ *
+ * @return a preconfigured {@link ConsoleHandler}.
+ */
+ public static ConsoleHandler createConsoleHandler() {
+ return new DefaultConsoleHandler();
+ }
+
+ @Override
+ public LogContextConfigurator create() {
+ var upstreamConfigurator = upstreamConfiguratorFactory.create();
+ return new LogContextConfigurator() {
+ @Override
+ public void configure(LogContext logContext, InputStream inputStream) {
+ upstreamConfigurator.configure(logContext, inputStream);
+ var logger = logContext.getLogger("");
+ logger.setHandlers(rootHandlers);
+ }
+ };
+ }
+
+ @Override
+ public int priority() {
+ return 50;
+ }
+}
diff --git a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultEmbeddedConfigurator.java b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultEmbeddedConfigurator.java
index e2ad986..79e9288 100644
--- a/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultEmbeddedConfigurator.java
+++ b/core/src/main/java/eu/mulk/quarkus/googlecloud/jsonlogging/logmanager/DefaultEmbeddedConfigurator.java
@@ -10,7 +10,7 @@ import org.jboss.logmanager.EmbeddedConfigurator;
import org.jboss.logmanager.handlers.ConsoleHandler;
/**
- * A convenient {@link EmbeddedConfigurator} for JBoss Log Manager.
+ * A convenient {@link EmbeddedConfigurator} for JBoss Log Manager Embedded (1.1.x and earlier).
*
* <p>You can register this class through the {@link java.util.ServiceLoader} mechanism as a
* provider of the {@link EmbeddedConfigurator} interface (under the name of {@code
@@ -25,7 +25,7 @@ public final class DefaultEmbeddedConfigurator implements EmbeddedConfigurator {
* Constructs a JBoss Log Manager configuration that uses {@link Formatter} and {@link
* ConsoleHandler} for log output.
*/
- @SuppressWarnings("java:S2095")
+ @SuppressWarnings({"java:S2095", "resource"})
public DefaultEmbeddedConfigurator() {
rootHandlers = new Handler[] {createConsoleHandler()};
}