logbook: Logbook doesn't work with spring boot 3
I’m following the documentation https://github.com/zalando/logbook#spring-boot-starter trying to make WebClient logging all exchanges, but here is a minimal code sample to make sure logbook + spring boot web client = nothing get logged
build.gradle.kts:
plugins {
java
id("org.springframework.boot") version "3.0.5"
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(platform("org.springframework.boot:spring-boot-dependencies:3.0.5"))
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.zalando:logbook-spring-boot-starter:2.16.0")
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
src/main/resources/application.yml:
spring:
main.web-application-type: none
logging.level:
org.zalando.logbook: trace
logbook:
format.style: http
filter.enabled: false
SpringApplication.java:
@SpringBootApplication
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class);
}
@Bean
public ApplicationRunner onStart(WebClient.Builder webClientBuilder) {
return args -> {
var webClient = webClientBuilder
.baseUrl("https://jsonplaceholder.typicode.com")
.build();
Todo resp = webClient
.get()
.uri("todos/{id}", 1)
.retrieve()
.bodyToMono(Todo.class)
.block();
System.out.println(resp.title);
};
}
}
class Todo {
public int id;
public int userId;
public String title;
public boolean completed;
}
As you can see, nothing got loggedAbout this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (2 by maintainers)
The autoconfiguration part should be fixed in the next release. I’ll resolve the issue. Feel free to reopen if you still need support here.
You’ve missed to post your logging (framework) configuration.
Hello @evkaky In order to make logbook work with webflux, you have just to include this dependency
logbook-spring-webflux. And injectLogbookExchangeFilterFunctionto your client. Here is the snippet ofSpringApplication.java:At startup you should have logs for Outgoing and Incoming Response. Hope that helps you.