Skip to content

Commit

Permalink
Allow for setting logging body limit programmatically
Browse files Browse the repository at this point in the history
Same as idea as quarkusio#36518
  • Loading branch information
geoand committed Oct 20, 2023
1 parent a924a94 commit cd750ba
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
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;
}

}

0 comments on commit cd750ba

Please sign in to comment.