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 body limit programmatically #36593

Merged
merged 1 commit into from
Oct 20, 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 @@ -268,6 +268,12 @@ static QuarkusRestClientBuilder newBuilder() {
*/
QuarkusRestClientBuilder loggingScope(LoggingScope loggingScope);

/**
* How many characters of the body should be logged. Message body can be large and can easily pollute the logs.
*
*/
QuarkusRestClientBuilder loggingBodyLimit(Integer limit);

/**
* 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 @@ -231,6 +231,12 @@ public QuarkusRestClientBuilder loggingScope(LoggingScope loggingScope) {
return this;
}

@Override
public QuarkusRestClientBuilder loggingBodyLimit(Integer limit) {
proxy.loggingBodyLimit(limit);
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 @@ -71,6 +71,7 @@ public class RestClientBuilderImpl implements RestClientBuilder {

private ClientLogger clientLogger;
private LoggingScope loggingScope;
private Integer loggingBodyLimit;

@Override
public RestClientBuilderImpl baseUrl(URL url) {
Expand Down Expand Up @@ -173,6 +174,11 @@ public RestClientBuilderImpl loggingScope(LoggingScope loggingScope) {
return this;
}

public RestClientBuilderImpl loggingBodyLimit(Integer limit) {
this.loggingBodyLimit = limit;
return this;
}

@Override
public RestClientBuilderImpl executorService(ExecutorService executor) {
throw new IllegalArgumentException("Specifying executor service is not supported. " +
Expand Down Expand Up @@ -346,9 +352,12 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
: LoggingScope.NONE;
}

Integer loggingBodySize = logging != null ? logging.bodyLimit : 100;
Integer effectiveLoggingBodyLimit = loggingBodyLimit; // if a limit was specified programmatically, it takes precedence
if (effectiveLoggingBodyLimit == null) {
effectiveLoggingBodyLimit = logging != null ? logging.bodyLimit : 100;
}
clientBuilder.loggingScope(effectiveLoggingScope);
clientBuilder.loggingBodySize(loggingBodySize);
clientBuilder.loggingBodySize(effectiveLoggingBodyLimit);
if (clientLogger != null) {
clientBuilder.clientLogger(clientLogger);
} else {
Expand Down Expand Up @@ -438,4 +447,5 @@ private MultiQueryParamMode toMultiQueryParamMode(QueryParamStyle queryParamStyl
}
return null;
}

}
Loading