Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for setting logging scope programmatically #36518

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading