Skip to content

Commit

Permalink
Merge pull request quarkusio#36518 from geoand/rest-client-programmat…
Browse files Browse the repository at this point in the history
…ic-logging

Allow for setting logging scope programmatically
  • Loading branch information
geoand authored Oct 17, 2023
2 parents 0a8efce + 59e2314 commit 5449d29
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.microprofile.rest.client.ext.QueryParamStyle;
import org.eclipse.microprofile.rest.client.spi.RestClientBuilderListener;
import org.jboss.resteasy.reactive.client.api.ClientLogger;
import org.jboss.resteasy.reactive.client.api.LoggingScope;

import io.quarkus.rest.client.reactive.runtime.QuarkusRestClientBuilderImpl;
import io.quarkus.rest.client.reactive.runtime.RestClientBuilderImpl;
Expand Down Expand Up @@ -259,6 +260,14 @@ static QuarkusRestClientBuilder newBuilder() {
*/
QuarkusRestClientBuilder clientLogger(ClientLogger clientLogger);

/**
* Specifies the client logger to use.
*
* @param loggingScope to use
* @return the current builder
*/
QuarkusRestClientBuilder loggingScope(LoggingScope loggingScope);

/**
* Based on the configured QuarkusRestClientBuilder, creates a new instance of the given REST interface to invoke API calls
* against.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
import org.eclipse.microprofile.rest.client.ext.QueryParamStyle;
import org.jboss.resteasy.reactive.client.api.ClientLogger;
import org.jboss.resteasy.reactive.client.api.LoggingScope;

import io.quarkus.rest.client.reactive.QuarkusRestClientBuilder;
import io.quarkus.rest.client.reactive.runtime.context.ClientHeadersFactoryContextResolver;
Expand Down Expand Up @@ -224,6 +225,12 @@ public QuarkusRestClientBuilder clientLogger(ClientLogger clientLogger) {
return this;
}

@Override
public QuarkusRestClientBuilder loggingScope(LoggingScope loggingScope) {
proxy.loggingScope(loggingScope);
return this;
}

@Override
public <T> T build(Class<T> clazz) throws IllegalStateException, RestClientDefinitionException {
return proxy.build(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class RestClientBuilderImpl implements RestClientBuilder {
private String nonProxyHosts;

private ClientLogger clientLogger;
private LoggingScope loggingScope;

@Override
public RestClientBuilderImpl baseUrl(URL url) {
Expand Down Expand Up @@ -167,6 +168,11 @@ public RestClientBuilderImpl clientLogger(ClientLogger clientLogger) {
return this;
}

public RestClientBuilderImpl loggingScope(LoggingScope loggingScope) {
this.loggingScope = loggingScope;
return this;
}

@Override
public RestClientBuilderImpl executorService(ExecutorService executor) {
throw new IllegalArgumentException("Specifying executor service is not supported. " +
Expand Down Expand Up @@ -333,10 +339,15 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
RestClientsConfig restClientsConfig = arcContainer.instance(RestClientsConfig.class).get();

RestClientLoggingConfig logging = restClientsConfig.logging;
LoggingScope loggingScope = logging != null ? logging.scope.map(LoggingScope::forName).orElse(LoggingScope.NONE)
: LoggingScope.NONE;

LoggingScope effectiveLoggingScope = loggingScope; // if a scope was specified programmatically, it takes precedence
if (effectiveLoggingScope == null) {
effectiveLoggingScope = logging != null ? logging.scope.map(LoggingScope::forName).orElse(LoggingScope.NONE)
: LoggingScope.NONE;
}

Integer loggingBodySize = logging != null ? logging.bodyLimit : 100;
clientBuilder.loggingScope(loggingScope);
clientBuilder.loggingScope(effectiveLoggingScope);
clientBuilder.loggingBodySize(loggingBodySize);
if (clientLogger != null) {
clientBuilder.clientLogger(clientLogger);
Expand Down

0 comments on commit 5449d29

Please sign in to comment.