Source:
private Mono<String> logRequest(final ClientLogger logger, final HttpRequest request) { int numericLogLevel = LoggingUtil.getEnvironmentLoggingLevel().toNumeric(); if (numericLogLevel == LogLevel.DISABLED.toNumeric() || numericLogLevel > LogLevel.INFORMATIONAL.toNumeric()) { return Mono.empty(); } StringBuilder requestLogMessage = new StringBuilder(); if (httpLogDetailLevel.shouldLogUrl()) { requestLogMessage.append(String.format("--> %s %s%n", request.getHttpMethod(), getRedactedUrl(request.getUrl()))); } addHeadersToLogMessage(request.getHeaders(), requestLogMessage, numericLogLevel); Mono<String> requestLoggingMono = Mono.defer(() -> Mono.just(requestLogMessage.toString())); if (httpLogDetailLevel.shouldLogBody()) { if (request.getBody() == null) { requestLogMessage.append(String.format("(empty body)%n--> END %s%n", request.getHttpMethod())); } else { String contentType = request.getHeaders().getValue("Content-Type"); long contentLength = getContentLength(logger, request.getHeaders()); if (bodyIsPrintable(contentType, contentLength)) { requestLoggingMono = FluxUtil.collectBytesInByteBufferStream(request.getBody()).flatMap(bytes -> Mono.just(requestLogMessage.append(String.format("%d-byte body:%n%s%n--> END %s%n", contentLength, new String(bytes, StandardCharsets.UTF_8), request.getHttpMethod())) .toString())); } else { requestLogMessage.append(String.format("%d-byte body: (content not logged)%n--> END %s%n", contentLength, request.getHttpMethod())); } } } return requestLoggingMono.doOnNext(logger::info); }

Target:
private Mono<String> logRequest(final ClientLogger logger, final HttpRequest request) { int numericLogLevel = LoggingUtil.getEnvironmentLoggingLevel().toNumeric(); if (shouldLoggingBeSkipped(numericLogLevel)) { return Mono.empty(); } StringBuilder requestLogMessage = new StringBuilder(); if (httpLogDetailLevel.shouldLogUrl()) { requestLogMessage.append("--> ") .append(request.getHttpMethod()) .append(" ") .append(getRedactedUrl(request.getUrl())) .append(System.lineSeparator()); } addHeadersToLogMessage(request.getHeaders(), requestLogMessage, numericLogLevel); Mono<String> requestLoggingMono = Mono.defer(() -> Mono.just(requestLogMessage.toString())); if (httpLogDetailLevel.shouldLogBody()) { if (request.getBody() == null) { requestLogMessage.append("(empty body)") .append(System.lineSeparator()) .append("--> END ") .append(request.getHttpMethod()) .append(System.lineSeparator()); } else { String contentType = request.getHeaders().getValue("Content-Type"); long contentLength = getContentLength(logger, request.getHeaders()); if (shouldBodyBeLogged(contentType, contentLength)) { requestLoggingMono = FluxUtil.collectBytesInByteBufferStream(request.getBody()).flatMap(bytes -> { requestLogMessage.append(contentLength) .append("-byte body:") .append(System.lineSeparator()) .append(prettyPrintIfNeeded(logger, contentType, new String(bytes, StandardCharsets.UTF_8))) .append(System.lineSeparator()) .append("--> END ") .append(request.getHttpMethod()) .append(System.lineSeparator()); return Mono.just(requestLogMessage.toString()); }); } else { requestLogMessage.append(contentLength) .append("-byte body: (content not logged)") .append(System.lineSeparator()) .append("--> END ") .append(request.getHttpMethod()) .append(System.lineSeparator()); } } } return requestLoggingMono.doOnNext(logger::info); }