Source:
private Mono<HttpResponse> logResponse(final ClientLogger logger, final HttpResponse response, long startNs) { int numericLogLevel = LoggingUtil.getEnvironmentLoggingLevel().toNumeric(); if (numericLogLevel == LogLevel.DISABLED.toNumeric() || numericLogLevel > LogLevel.INFORMATIONAL.toNumeric()) { return Mono.just(response); } long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs); String contentLengthString = response.getHeaderValue("Content-Length"); String bodySize = (CoreUtils.isNullOrEmpty(contentLengthString)) ? "unknown-length" : contentLengthString + "-byte"; StringBuilder responseLogMessage = new StringBuilder(); if (httpLogDetailLevel.shouldLogUrl()) { responseLogMessage.append(String.format("<-- %d %s (%d ms, %s body)%n", response.getStatusCode(), getRedactedUrl(response.getRequest().getUrl()), tookMs, bodySize)); } addHeadersToLogMessage(response.getHeaders(), responseLogMessage, numericLogLevel); Mono<String> responseLoggingMono = Mono.defer(() -> Mono.just(responseLogMessage.toString())); if (httpLogDetailLevel.shouldLogBody()) { final String contentTypeHeader = response.getHeaderValue("Content-Type"); if (bodyIsPrintable(contentTypeHeader, getContentLength(logger, response.getHeaders()))) { final HttpResponse bufferedResponse = response.buffer(); responseLoggingMono = bufferedResponse.getBodyAsString().flatMap(body -> Mono.just(responseLogMessage.append(String.format("Response body:%n%s%n<-- END HTTP", prettyPrintIfNeeded(logger, contentTypeHeader, body))) .toString())) .switchIfEmpty(responseLoggingMono); } else { responseLogMessage.append("(body content not logged)") .append(System.lineSeparator()) .append("<-- END HTTP"); } } else { responseLogMessage.append("<-- END HTTP"); } return responseLoggingMono.doOnNext(logger::info).thenReturn(response); }

Target:
private Mono<HttpResponse> logResponse(final ClientLogger logger, final HttpResponse response, long startNs) { int numericLogLevel = LoggingUtil.getEnvironmentLoggingLevel().toNumeric(); if (shouldLoggingBeSkipped(numericLogLevel)) { return Mono.just(response); } long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs); String contentLengthString = response.getHeaderValue("Content-Length"); String bodySize = (CoreUtils.isNullOrEmpty(contentLengthString)) ? "unknown-length body" : contentLengthString + "-byte body"; StringBuilder responseLogMessage = new StringBuilder(); if (httpLogDetailLevel.shouldLogUrl()) { responseLogMessage.append("<-- ") .append(response.getStatusCode()) .append(" ") .append(getRedactedUrl(response.getRequest().getUrl())) .append(" (") .append(tookMs) .append(" ms, ") .append(bodySize) .append(")") .append(System.lineSeparator()); } addHeadersToLogMessage(response.getHeaders(), responseLogMessage, numericLogLevel); Mono<String> responseLoggingMono = Mono.defer(() -> Mono.just(responseLogMessage.toString())); if (httpLogDetailLevel.shouldLogBody()) { final String contentTypeHeader = response.getHeaderValue("Content-Type"); if (shouldBodyBeLogged(contentTypeHeader, getContentLength(logger, response.getHeaders()))) { final HttpResponse bufferedResponse = response.buffer(); responseLoggingMono = bufferedResponse.getBodyAsString().flatMap(body -> { responseLogMessage.append("Response body:") .append(System.lineSeparator()) .append(prettyPrintIfNeeded(logger, contentTypeHeader, body)) .append(System.lineSeparator()) .append("<-- END HTTP"); return Mono.just(responseLogMessage.toString()); }).switchIfEmpty(responseLoggingMono); } else { responseLogMessage.append("(body content not logged)") .append(System.lineSeparator()) .append("<-- END HTTP"); } } else { responseLogMessage.append("<-- END HTTP"); } return responseLoggingMono.doOnNext(logger::info).thenReturn(response); }