Skip to content

Commit 819d283

Browse files
committed
Adding possibility to load jackson modules available in the classpath.
1 parent c5564cf commit 819d283

File tree

5 files changed

+130
-42
lines changed

5 files changed

+130
-42
lines changed

deployment/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<artifactId>quarkus-logging-json</artifactId>
2626
<version>3.3.2-SNAPSHOT</version>
2727
</dependency>
28+
<dependency>
29+
<groupId>io.quarkus</groupId>
30+
<artifactId>quarkus-jackson-spi</artifactId>
31+
<optional>true</optional>
32+
</dependency>
2833
<!-- test dependencies -->
2934
<dependency>
3035
<groupId>io.quarkus</groupId>

deployment/src/main/java/io/quarkiverse/loggingjson/deployment/LoggingJsonProcessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import java.util.Collection;
44

5+
import jakarta.inject.Inject;
6+
57
import org.jboss.jandex.ClassInfo;
68

79
import io.quarkiverse.loggingjson.JsonFactory;
810
import io.quarkiverse.loggingjson.LoggingJsonRecorder;
11+
import io.quarkiverse.loggingjson.deployment.config.ConfigJackson;
912
import io.quarkiverse.loggingjson.jackson.JacksonJsonFactory;
1013
import io.quarkiverse.loggingjson.jsonb.JsonbJsonFactory;
1114
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
15+
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
1216
import io.quarkus.deployment.Capabilities;
1317
import io.quarkus.deployment.Capability;
1418
import io.quarkus.deployment.annotations.BuildProducer;
@@ -20,11 +24,15 @@
2024
import io.quarkus.deployment.builditem.LogConsoleFormatBuildItem;
2125
import io.quarkus.deployment.builditem.LogFileFormatBuildItem;
2226
import io.quarkus.deployment.builditem.LogSocketFormatBuildItem;
27+
import io.quarkus.jackson.spi.ClassPathJacksonModuleBuildItem;
2328

2429
class LoggingJsonProcessor {
2530

2631
private static final String FEATURE = "logging-json";
2732

33+
@Inject
34+
ConfigJackson configJackson;
35+
2836
@BuildStep
2937
FeatureBuildItem feature() {
3038
return new FeatureBuildItem(FEATURE);
@@ -48,6 +56,15 @@ LogSocketFormatBuildItem setUpSocketFormatter(Capabilities capabilities, Logging
4856
return new LogSocketFormatBuildItem(recorder.initializeSocketJsonLogging(jsonFactory(capabilities)));
4957
}
5058

59+
@BuildStep
60+
void autoRegisterModules(BuildProducer<ClassPathJacksonModuleBuildItem> classPathJacksonModules) {
61+
for (String moduleClassName : configJackson.modules()) {
62+
if (QuarkusClassLoader.isClassPresentAtRuntime(moduleClassName)) {
63+
classPathJacksonModules.produce(new ClassPathJacksonModuleBuildItem(moduleClassName));
64+
}
65+
}
66+
}
67+
5168
private JsonFactory jsonFactory(Capabilities capabilities) {
5269
if (capabilities.isPresent(Capability.JACKSON)) {
5370
return new JacksonJsonFactory();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.quarkiverse.loggingjson.deployment.config;
2+
3+
import java.util.List;
4+
5+
import io.quarkus.runtime.annotations.ConfigPhase;
6+
import io.quarkus.runtime.annotations.ConfigRoot;
7+
import io.smallrye.config.ConfigMapping;
8+
import io.smallrye.config.WithDefault;
9+
import io.smallrye.config.WithName;
10+
11+
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
12+
@ConfigMapping(prefix = "quarkus.log.json.jackson.object.mapper")
13+
public interface ConfigJackson {
14+
15+
/**
16+
* List of jackson modules to register.
17+
*
18+
* @return module names list
19+
*/
20+
@WithName("modules")
21+
@WithDefault("com.fasterxml.jackson.datatype.jsr310.JavaTimeModule,com.fasterxml.jackson.datatype.jdk8.Jdk8Module,com.fasterxml.jackson.module.paramnames.ParameterNamesModule")
22+
List<String> modules();
23+
24+
}

docs/modules/ROOT/pages/includes/quarkus-logging-json.adoc

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ h|[.header-title]##Configuration property##
77
h|Type
88
h|Default
99

10+
a|icon:lock[title=Fixed at build time] [[quarkus-logging-json_quarkus-log-json-jackson-object-mapper-modules]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-jackson-object-mapper-modules[`quarkus.log.json.jackson.object.mapper.modules`]##
11+
ifdef::add-copy-button-to-config-props[]
12+
config_property_copy_button:+++quarkus.log.json.jackson.object.mapper.modules+++[]
13+
endif::add-copy-button-to-config-props[]
14+
15+
16+
[.description]
17+
--
18+
List of jackson modules to register.
19+
20+
21+
ifdef::add-copy-button-to-env-var[]
22+
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_JACKSON_OBJECT_MAPPER_MODULES+++[]
23+
endif::add-copy-button-to-env-var[]
24+
ifndef::add-copy-button-to-env-var[]
25+
Environment variable: `+++QUARKUS_LOG_JSON_JACKSON_OBJECT_MAPPER_MODULES+++`
26+
endif::add-copy-button-to-env-var[]
27+
--
28+
|list of string
29+
|`+++com.fasterxml.jackson.datatype.jsr310.JavaTimeModule+++`, `+++com.fasterxml.jackson.datatype.jdk8.Jdk8Module+++`, `+++com.fasterxml.jackson.module.paramnames.ParameterNamesModule+++`
30+
1031
a| [[quarkus-logging-json_quarkus-log-json-console-enabled]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-console-enabled[`quarkus.log.json.console.enabled`]##
1132
ifdef::add-copy-button-to-config-props[]
1233
config_property_copy_button:+++quarkus.log.json.console.enabled+++[]
@@ -932,6 +953,27 @@ endif::add-copy-button-to-env-var[]
932953
|`+++
933954
+++`
934955

956+
a| [[quarkus-logging-json_quarkus-log-json-log-format]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-log-format[`quarkus.log.json.log-format`]##
957+
ifdef::add-copy-button-to-config-props[]
958+
config_property_copy_button:+++quarkus.log.json.log-format+++[]
959+
endif::add-copy-button-to-config-props[]
960+
961+
962+
[.description]
963+
--
964+
Support changing logging format.
965+
966+
967+
ifdef::add-copy-button-to-env-var[]
968+
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_LOG_FORMAT+++[]
969+
endif::add-copy-button-to-env-var[]
970+
ifndef::add-copy-button-to-env-var[]
971+
Environment variable: `+++QUARKUS_LOG_JSON_LOG_FORMAT+++`
972+
endif::add-copy-button-to-env-var[]
973+
--
974+
a|`default`, `ecs`
975+
|`+++default+++`
976+
935977
h|[[quarkus-logging-json_section_quarkus-log-json-additional-field]] [.section-name.section-level0]##link:#quarkus-logging-json_section_quarkus-log-json-additional-field[For adding fields to the json output directly from the config]##
936978
h|Type
937979
h|Default
@@ -979,26 +1021,5 @@ a|`string`, `int`, `long`, `float`, `double`
9791021
|`+++string+++`
9801022

9811023

982-
a| [[quarkus-logging-json_quarkus-log-json-log-format]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-log-format[`quarkus.log.json.log-format`]##
983-
ifdef::add-copy-button-to-config-props[]
984-
config_property_copy_button:+++quarkus.log.json.log-format+++[]
985-
endif::add-copy-button-to-config-props[]
986-
987-
988-
[.description]
989-
--
990-
Support changing logging format.
991-
992-
993-
ifdef::add-copy-button-to-env-var[]
994-
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_LOG_FORMAT+++[]
995-
endif::add-copy-button-to-env-var[]
996-
ifndef::add-copy-button-to-env-var[]
997-
Environment variable: `+++QUARKUS_LOG_JSON_LOG_FORMAT+++`
998-
endif::add-copy-button-to-env-var[]
999-
--
1000-
a|`default`, `ecs`
1001-
|`+++default+++`
1002-
10031024
|===
10041025

docs/modules/ROOT/pages/includes/quarkus-logging-json_quarkus.log.adoc

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ h|[.header-title]##Configuration property##
77
h|Type
88
h|Default
99

10+
a|icon:lock[title=Fixed at build time] [[quarkus-logging-json_quarkus-log-json-jackson-object-mapper-modules]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-jackson-object-mapper-modules[`quarkus.log.json.jackson.object.mapper.modules`]##
11+
ifdef::add-copy-button-to-config-props[]
12+
config_property_copy_button:+++quarkus.log.json.jackson.object.mapper.modules+++[]
13+
endif::add-copy-button-to-config-props[]
14+
15+
16+
[.description]
17+
--
18+
List of jackson modules to register.
19+
20+
21+
ifdef::add-copy-button-to-env-var[]
22+
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_JACKSON_OBJECT_MAPPER_MODULES+++[]
23+
endif::add-copy-button-to-env-var[]
24+
ifndef::add-copy-button-to-env-var[]
25+
Environment variable: `+++QUARKUS_LOG_JSON_JACKSON_OBJECT_MAPPER_MODULES+++`
26+
endif::add-copy-button-to-env-var[]
27+
--
28+
|list of string
29+
|`+++com.fasterxml.jackson.datatype.jsr310.JavaTimeModule+++`, `+++com.fasterxml.jackson.datatype.jdk8.Jdk8Module+++`, `+++com.fasterxml.jackson.module.paramnames.ParameterNamesModule+++`
30+
1031
a| [[quarkus-logging-json_quarkus-log-json-console-enabled]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-console-enabled[`quarkus.log.json.console.enabled`]##
1132
ifdef::add-copy-button-to-config-props[]
1233
config_property_copy_button:+++quarkus.log.json.console.enabled+++[]
@@ -932,6 +953,27 @@ endif::add-copy-button-to-env-var[]
932953
|`+++
933954
+++`
934955

956+
a| [[quarkus-logging-json_quarkus-log-json-log-format]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-log-format[`quarkus.log.json.log-format`]##
957+
ifdef::add-copy-button-to-config-props[]
958+
config_property_copy_button:+++quarkus.log.json.log-format+++[]
959+
endif::add-copy-button-to-config-props[]
960+
961+
962+
[.description]
963+
--
964+
Support changing logging format.
965+
966+
967+
ifdef::add-copy-button-to-env-var[]
968+
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_LOG_FORMAT+++[]
969+
endif::add-copy-button-to-env-var[]
970+
ifndef::add-copy-button-to-env-var[]
971+
Environment variable: `+++QUARKUS_LOG_JSON_LOG_FORMAT+++`
972+
endif::add-copy-button-to-env-var[]
973+
--
974+
a|`default`, `ecs`
975+
|`+++default+++`
976+
935977
h|[[quarkus-logging-json_section_quarkus-log-json-additional-field]] [.section-name.section-level0]##link:#quarkus-logging-json_section_quarkus-log-json-additional-field[For adding fields to the json output directly from the config]##
936978
h|Type
937979
h|Default
@@ -979,26 +1021,5 @@ a|`string`, `int`, `long`, `float`, `double`
9791021
|`+++string+++`
9801022

9811023

982-
a| [[quarkus-logging-json_quarkus-log-json-log-format]] [.property-path]##link:#quarkus-logging-json_quarkus-log-json-log-format[`quarkus.log.json.log-format`]##
983-
ifdef::add-copy-button-to-config-props[]
984-
config_property_copy_button:+++quarkus.log.json.log-format+++[]
985-
endif::add-copy-button-to-config-props[]
986-
987-
988-
[.description]
989-
--
990-
Support changing logging format.
991-
992-
993-
ifdef::add-copy-button-to-env-var[]
994-
Environment variable: env_var_with_copy_button:+++QUARKUS_LOG_JSON_LOG_FORMAT+++[]
995-
endif::add-copy-button-to-env-var[]
996-
ifndef::add-copy-button-to-env-var[]
997-
Environment variable: `+++QUARKUS_LOG_JSON_LOG_FORMAT+++`
998-
endif::add-copy-button-to-env-var[]
999-
--
1000-
a|`default`, `ecs`
1001-
|`+++default+++`
1002-
10031024
|===
10041025

0 commit comments

Comments
 (0)