Skip to content

Commit

Permalink
Rest client per CDI injected client logging configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lasteris committed Jan 11, 2025
1 parent 4b0ff98 commit 1d1c6be
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/src/main/asciidoc/rest-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1845,14 +1845,20 @@ As HTTP messages can have large bodies, we limit the amount of body characters l

NOTE: REST Client is logging the traffic with level DEBUG and does not alter logger properties. You may need to adjust your logger configuration to use this feature.

These configuration properties work globally for all clients injected by CDI.
If you want configure logging for particular one (but only for CDI injected), you should do it by specifying named "client" properties, also known as `quarkus.rest-client."client".logging.*` properties.

An example logging configuration:

[source,properties]
----
quarkus.rest-client.logging.scope=request-response
quarkus.rest-client.logging.body-limit=50
quarkus.rest-client.extensions-api.scope=all
quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG
quarkus.log.console.level=DEBUG
----

[TIP]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,11 @@ default Optional<String> uriReload() {
*/
@WithDefault("${microprofile.rest.client.disable.default.mapper:false}")
Boolean disableDefaultMapper();

/**
* Logging configuration.
*/
Optional<RestClientLoggingConfig> logging();
}

class RestClientKeysProvider implements Supplier<Iterable<String>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
clientBuilder.register(new MicroProfileRestClientResponseFilter(exceptionMappers));
clientBuilder.followRedirects(followRedirects);

RestClientsConfig.RestClientLoggingConfig logging = restClients.logging();
RestClientsConfig.RestClientLoggingConfig logging = getConfiguration().hasProperty(QuarkusRestClientProperties.LOGGING)
? (RestClientsConfig.RestClientLoggingConfig) getConfiguration()
.getProperty(QuarkusRestClientProperties.LOGGING)
: restClients.logging();

LoggingScope effectiveLoggingScope = loggingScope; // if a scope was specified programmatically, it takes precedence
if (effectiveLoggingScope == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,19 @@ void configureBuilder(QuarkusRestClientBuilder builder) {
configureQueryParamStyle(builder);
configureProxy(builder);
configureShared(builder);
configureLogging(builder);
configureCustomProperties(builder);
}

private void configureLogging(QuarkusRestClientBuilder builder) {
Optional<RestClientsConfig.RestClientLoggingConfig> logging = restClientConfig.logging();
if (logging.isPresent()) {
builder.property(QuarkusRestClientProperties.LOGGING, logging.get());
} else if (configRoot.logging() != null) {
builder.property(QuarkusRestClientProperties.LOGGING, configRoot.logging());
}
}

private void configureCustomProperties(QuarkusRestClientBuilder builder) {
Optional<String> encoder = oneOf(restClientConfig.multipartPostEncoderMode(), configRoot.multipartPostEncoderMode());
if (encoder != null && encoder.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public class QuarkusRestClientProperties {
*/
public static final String CAPTURE_STACKTRACE = "io.quarkus.rest.client.capture-stacktrace";

/**
* logging configuration
*/
public static final String LOGGING = "io.quarkus.rest.client.logging";

}

0 comments on commit 1d1c6be

Please sign in to comment.