diff --git a/core/runtime/pom.xml b/core/runtime/pom.xml
index 52401e7cc11bb..8600c36436586 100644
--- a/core/runtime/pom.xml
+++ b/core/runtime/pom.xml
@@ -43,6 +43,10 @@
io.smallrye
smallrye-config
+
+ org.glassfish
+ javax.json
+
org.jboss.logging
jboss-logging
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java
index 553259b70d96e..9e666ca741271 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/ConsoleConfig.java
@@ -36,6 +36,17 @@ public class ConsoleConfig {
@ConfigItem(defaultValue = "%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n")
String format;
+ /**
+ * The type of output format to use.
+ */
+ @ConfigItem(defaultValue = "text")
+ FormatType formatType;
+
+ /**
+ * JSON format configuration.
+ */
+ JsonConfig json;
+
/**
* The console log level
*/
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/FormatType.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/FormatType.java
new file mode 100644
index 0000000000000..4db8088833aa8
--- /dev/null
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/FormatType.java
@@ -0,0 +1,26 @@
+package io.quarkus.runtime.logging;
+
+/**
+ * The type of formatter to use.
+ */
+public enum FormatType {
+ /**
+ * Format in text for person-readability.
+ */
+ TEXT,
+ /**
+ * Format in JSON for machine-readability.
+ */
+ JSON,
+ ;
+
+ public static FormatType of(String str) {
+ if (str.equalsIgnoreCase("text")) {
+ return TEXT;
+ } else if (str.equalsIgnoreCase("json")) {
+ return JSON;
+ } else {
+ throw new IllegalArgumentException("Unrecognized value: " + str);
+ }
+ }
+}
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/JsonConfig.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/JsonConfig.java
new file mode 100644
index 0000000000000..afc8eff18bafb
--- /dev/null
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/JsonConfig.java
@@ -0,0 +1,16 @@
+package io.quarkus.runtime.logging;
+
+import io.quarkus.runtime.annotations.ConfigGroup;
+import io.quarkus.runtime.annotations.ConfigItem;
+
+/**
+ * JSON-specific logging configuration.
+ */
+@ConfigGroup
+public class JsonConfig {
+ /**
+ * Enable logging of call details (method name, class name, etc.) into the JSON output.
+ */
+ @ConfigItem
+ public boolean callDetails;
+}
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupTemplate.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupTemplate.java
index 5b73e09a91d01..8c895616ba81a 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupTemplate.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupTemplate.java
@@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.ErrorManager;
+import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
@@ -15,6 +16,7 @@
import org.jboss.logmanager.Logger;
import org.jboss.logmanager.errormanager.OnlyOnceErrorManager;
import org.jboss.logmanager.formatters.ColorPatternFormatter;
+import org.jboss.logmanager.formatters.JsonFormatter;
import org.jboss.logmanager.formatters.PatternFormatter;
import org.jboss.logmanager.handlers.ConsoleHandler;
import org.jboss.logmanager.handlers.FileHandler;
@@ -50,11 +52,20 @@ public void initializeLogging(LogConfig config) {
}
ArrayList handlers = new ArrayList<>(2);
if (config.console.enable) {
- final PatternFormatter formatter;
- if (config.console.color && System.console() != null) {
- formatter = new ColorPatternFormatter(config.console.darken, config.console.format);
+ final Formatter formatter;
+ if (config.console.formatType == FormatType.JSON) {
+ JsonFormatter jsonFormatter = new JsonFormatter();
+ if (config.console.json.callDetails) {
+ jsonFormatter.setPrintDetails(true);
+ }
+ formatter = jsonFormatter;
} else {
- formatter = new PatternFormatter(config.console.format);
+ assert config.console.formatType == FormatType.TEXT;
+ if (config.console.color && System.console() != null) {
+ formatter = new ColorPatternFormatter(config.console.darken, config.console.format);
+ } else {
+ formatter = new PatternFormatter(config.console.format);
+ }
}
final ConsoleHandler handler = new ConsoleHandler(formatter);
handler.setLevel(config.console.level);
diff --git a/docs/src/main/asciidoc/logging-guide.adoc b/docs/src/main/asciidoc/logging-guide.adoc
index a258d5f3df52a..73fd7308c2a5c 100644
--- a/docs/src/main/asciidoc/logging-guide.adoc
+++ b/docs/src/main/asciidoc/logging-guide.adoc
@@ -21,9 +21,10 @@ Console logging is enabled by default. To configure or disable it, the followin
|===
|Property Name|Default|Description
|quarkus.log.console.enable|true|Determine whether console logging is enabled.
-|quarkus.log.console.format|%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n|The format pattern to use for logging to the console; see <>.
+|quarkus.log.console.format|%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] (%t) %s%e%n|The format pattern to use for `text` logging to the console; see <>.
+|quarkus.log.console.format-type|text|The type of formatter to use for the console; valid values are `text` or `json` (see <>).
|quarkus.log.console.level|INFO|The minimum log level to display to the console.
-|quarkus.log.console.color|true|Allow color rendering to be used on the console, if it is supported by the terminal.
+|quarkus.log.console.color|true|Allow color rendering to be used on the console in `text` mode, if it is supported by the terminal.
|===
=== File configuration
@@ -39,6 +40,17 @@ Logging to a file is also supported but not enabled by default. To configure or
|quarkus.log.file.path|quarkus.log|The path of the log file.
|===
+[id="json_config"]
+=== JSON configuration
+
+When outputting in JSON format, it is possible to configure additional properties.
+
+[cols="