1

Is there a way to log only the body with feign spring client? Using the Log.level I seem to only be able to only include the body with the full logging and in that case it is printing the headers too. Which I don't want to see in the logs.

Funzo
  • 1,190
  • 2
  • 14
  • 25

1 Answers1

0

The default Logger uses the Log.Level to control what is logged and works in a way that is additive. This means that going up in level logs more information. To customize this behavior, you will need to provide your own Logger implementation. Specifically, you can extend one of the included loggers and customize the logAndRebufferResponse method:

public class MyLogger extends JavaLogger {
     protected Response logAndRebufferResponse(String configKey,
                                        Level logLevel,
                                        Response response,
                                        long elapsedTime) {
        // only log the response data, skip the headers
     }
}

Next, include this logger in your Feign configuration.

 API api = Feign.builder()
                 .logger(new MyLogger())
                 .logLevel(Logger.Level.FULL)
                 .target(API.class, "https://api.example.com");

All instances of this Feign Client will use your logger now.

Kevin Davis
  • 1,193
  • 8
  • 14