@@ -712,6 +712,76 @@ a heartbeat and ignore.
712712
713713
714714
715+ [[webflux-logging]]
716+ === Logging
717+ [.small]#<<web.adoc#mvc-logging,Same in Spring MVC>>#
718+ 
719+ DEBUG level logging in Spring WebFlux is designed to be compact, minimal, and
720+ human-friendly. It focuses on high value bits of information that are useful over and
721+ over again vs others that are useful only when debugging a specific issue.
722+ 
723+ TRACE level logging generally follows the same principles as DEBUG (and for example also
724+ should not be a firehose) but can be used for debugging any issue. In addition some log
725+ messages may show a different level of detail at TRACE vs DEBUG.
726+ 
727+ Good logging comes from the experience of using the logs. If you spot anything that does
728+ not meet the stated goals, please let us know.
729+ 
730+ 
731+ [[webflux-logging-id]]
732+ ==== Log Id
733+ 
734+ In WebFlux, a single request may be executed over multiple threads and the thread id
735+ is not useful for correlating log messages that belong to a specific request. This is why
736+ WebFlux log messages are prefixed with a request specific id by default.
737+ 
738+ On the server side the log id is stored in the `ServerWebExchange` attribute
739+ {api-spring-framework}/web/server/ServerWebExchange.html#LOG_ID_ATTRIBUTE[LOG_ID_ATTRIBUTE]
740+ while a fully formatted prefix based on that id is available via
741+ `ServerWebExchange#getLogPrefix()`. On the `WebClient` side, the log id is stored in the
742+ `ClientRequest` attribute
743+ {api-spring-framework}/web/reactive/function/client/ClientRequest.html#LOG_ID_ATTRIBUTE[LOG_ID_ATTRIBUTE]
744+ while a fully formatted prefix is available via `ClientRequest#logPrefix()`.
745+ 
746+ 
747+ [[webflux-logging-sensitive-data]]
748+ ==== Sensitive Data
749+ [.small]#<<web.adoc#mvc-logging-sensitive-data,Same in Spring MVC>>#
750+ 
751+ DEBUG and TRACE logging may log sensitive information. This is why form parameters and
752+ headers are masked by default and their logging in full must be enabled explicitly.
753+ 
754+ For server side requests:
755+ 
756+ [source,java,indent=0]
757+ [subs="verbatim,quotes"]
758+ ---- 
759+ @Configuration 
760+ @EnableWebFlux 
761+ class MyConfig implements WebFluxConfigurer { 
762+ 
763+ 	@Override 
764+ 	public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) { 
765+ 		configurer.defaultCodecs().enableLoggingRequestDetails(true); 
766+ 	} 
767+ } 
768+ ---- 
769+ 
770+ For client side requests:
771+ 
772+ [source,java,indent=0]
773+ [subs="verbatim,quotes"]
774+ ---- 
775+ Consumer<ClientCodecConfigurer> consumer = configurer -> 
776+ 		configurer.defaultCodecs().enableLoggingRequestDetails(true); 
777+ 
778+ WebClient webClient = WebClient.builder() 
779+ 		.exchangeStrategies(ExchangeStrategies.builder().codecs(consumer).build()) 
780+ 		.build(); 
781+ ---- 
782+ 
783+ 
784+ 
715785
716786[[webflux-dispatcher-handler]]
717787== DispatcherHandler
0 commit comments