From 73095955bfd37af2e76e2066fe6f5772a01e16ff Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 12 Feb 2018 15:56:04 -0500 Subject: [PATCH] Refine logging in ExchangeFunctions Notably do not log error signal since we are letting that propagate. Also improve logging messages vs relying on the log operator. Issue: SPR-16484 --- .../function/client/ExchangeFunctions.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java index 542d051288..97662ed879 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunctions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,11 @@ package org.springframework.web.reactive.function.client; -import java.util.logging.Level; - +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import reactor.core.publisher.Mono; +import org.springframework.http.HttpStatus; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.util.Assert; @@ -29,10 +30,14 @@ import org.springframework.util.Assert; * {@code ClientHttpConnector}. * * @author Arjen Poutsma + * @author Rossen Stoyanchev * @since 5.0 */ public abstract class ExchangeFunctions { + private static final Log logger = LogFactory.getLog(ExchangeFunctions.class); + + /** * Create a new {@link ExchangeFunction} with the given connector. This method uses * {@linkplain ExchangeStrategies#withDefaults() default strategies}. @@ -73,9 +78,16 @@ public abstract class ExchangeFunctions { return this.connector .connect(request.method(), request.url(), clientHttpRequest -> request.writeTo(clientHttpRequest, this.strategies)) - .log("org.springframework.web.reactive.function.client", Level.FINE) - .map(clientHttpResponse -> new DefaultClientResponse(clientHttpResponse, - this.strategies)); + .doOnSubscribe(subscription -> logger.debug("Subscriber present")) + .doOnRequest(n -> logger.debug("Demand signaled")) + .doOnCancel(() -> logger.debug("Cancelling request")) + .map(response -> { + HttpStatus status = response.getStatusCode(); + if (logger.isDebugEnabled()) { + logger.debug("Response received, status: " + status + " " + status.getReasonPhrase()); + } + return new DefaultClientResponse(response, this.strategies); + }); } }