Logbook is not logging my request and responses
alimohsin25 opened this issue · 2 comments
Hi,
I am using java 18 with spring boot version 2.6.7. I have added following dependencies in my pom.xml:-
<dependency> <groupId>org.zalando</groupId> <artifactId>logbook-spring-boot-starter</artifactId> <version>3.0.0</version> </dependency> <dependency> <groupId>org.zalando</groupId> <artifactId>logbook-json</artifactId> <version>3.0.0</version> </dependency>
After adding these dependencies, I added following configurations in application.properties:-
logging.level.org.zalando.logbook=TRACE logbook.filter.enabled=true logbook.secure-filter.enabled=true
I am using log4j with following configs:-
log4j.rootLogger=TRACE, file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=logs/application1.log log4j.appender.file.MaxFileSize=5MB log4j.appender.file.MaxBackupIndex=10 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
Can any one please guide what I am doing wrong as I am unable to run Logbook and nothing is being logged neither in log file nor in console.
Regards,
Mohsin
Hi @alimohsin25, try adding
<dependency>
<groupId>org.zalando</groupId>
<artifactId>logbook-servlet</artifactId>
<version>${logbook.version}</version>
<classifier>javax</classifier>
</dependency>
It's a necessary change for older Spring versions since logbook 3 (see https://github.com/zalando/logbook#spring-5--spring-boot-2-support)
Also, it looks like we removed spring.factories
file while adding the support for Spring Boot 3, I'm adding it back in #1533. In the meantime, you could force Spring to use the Logbook's autoconfiguration file by adding @ImportAutoConfiguration(classes = LogbookAutoConfiguration.class)
to your application.
Thank You very much Karen for your timely help. Above steps resolved my issue. I appreciate your help.
Regards,
Mohsin