Open aldex32 opened 4 months ago
I've recently integrated LogBook into our Spring Boot project. My goal was to enable logging specifically for WebFlux without affecting all Spring Boot requests and responses.
Here's what I did:
Added the LogBook dependency for WebFlux in build.gradle.kts
:
implementation("org.zalando:logbook-spring-webflux:3.9.0")
Configured the logbook.filter.enabled property in application.properties`
initialize the LogBook bean and hooked that in LogbookExchangeFilterFunction filters.
Observations:
In summary, just adding the LogBook WebFlux dependency was enough to get logging working for WebClient without needing additional configurations however logbook.filter.enabled
property does not have any impact on ON/OFF logbook webflux logging.
here is my demo project for reference : https://github.com/adityachaudhari24/logbook-demos/blob/master/src/main/resources/application.properties .
Thanks @aldex32 for opening the feature,
Something similar I am looking, where just by property logbook.filter.enabled
disable my logbook filters in the webflix must stop logging.
l want to upvote this feature, I will try to contribute on this.
One way to disable is using WebClientCustomizer
bean with conditional on property. See Kotlin example:
@Bean
@ConditionalOnProperty(name = ["logbook.filter.enabled"], havingValue = "true", matchIfMissing = true)
fun logbookExchangeFilter(logbook: Logbook) =
WebClientCustomizer { it.filter(LogbookExchangeFilterFunction(logbook)) }
So if the property logbook.filter.enabled
is not false, a WebClientCustomizer
bean will be created which will customize WebClient.Builder
.
I would like to have a logbook property where I can both disable servlet filters but also
LogbookExchangeFilterFunction
. Seems likelogbook.filter.enabled
property is only intended for servlet filter support as far as I can see inLogbookAutoConfiguration
. Can this property also be used for http client logging?Detailed Description
I am using
logbook-spring-boot-starter@3.9.0
together withlogbook-spring-webflux@3.9.0
. And when I setlogbook.filter.enabled=false
, only the servlet logging gets disabled, but theWebClient
logging still occurs. I am not sure if this is as by design or is a bug.Context
This is important because users of this library can use a single property to enable/disable request/response logging. And since
LogbookExchangeFilterFunction
requires alogbook
bean which is autoconfigured based on properties, why not leveraging the property to disable/enable the logging.Your Environment