How to filter response bodies by URL in zalando logbook

1.9k Views Asked by At

When creating the Logbook object in our configuration, we can define a set of Conditions to exclude from logging. This allows us to give regex patterns that can be used to block logging on requests to specific urls.

Is there a way to also exclude responses by the specific urls we are sending them back to in a similar fashion?

https://github.com/zalando/logbook

Specifically I've been looking into their Responsefilter class and have managed to filter/mask the body of all outgoing responses but I can't seem to figure out how to do it for only certain calls/urls.

2

There are 2 best solutions below

0
Rafal Bodzak On

What you need is to implement your own org.zalando.logbook.Strategy.

0
Tanimak On

If you are using spring boot you can easily do it by defining the url paths in configurations. In application.yml

logbook:
  exclude:
    - /payment/**
    - /actuator/health
    - /actuator/info
    - /admin/**
    - /swagger-ui/**

Note that these needs to be the path elements of your URLs after removing the host.

For more information on logging request response with logbook read this article https://medium.com/@pramodyahk/configure-request-response-logging-for-spring-boot-quickly-using-logbook-183503c4676c