HTTP logging & connection timeout in Feign Clients with Spring Boot

Carvia Tech | December 03, 2019 | 2 min read | 13 views


we will cover how to enable network http request logging, connection timeout, read timeout for requests generated by feign Clients in Spring Boot applications.

Logging levels

Feign provides the following logging levels for debugging/troubleshooting purpose:

NONE

No logging. This is the default behaviour.

BASIC

Log only the request method and URL and the response status code and execution time.

HEADERS

Log the basic information along with request and response headers.

FULL

Log the headers, body, and metadata for both requests and responses.

There are two ways we can configure the logging level for feign clients - using properties and using java configuration. Lets discuss them both, one by one.

The very first step is to enable DEBUG logging for FeignClient in spring boot application properties.

application.yml
logging.level.package-path.FooClient: DEBUG

Logging will not work without this configuration.

Using application properties

Using application.yml, we can configure different attributes for feign client - at individual level or at global default level.

application.yml - Per Feign client configuration
feign:
  client:
    config:
      name_of_your_feign_client:  (1)
        connectTimeout: 5000
        readTimeout: 5000
        loggerLevel: basic
1 This is the name of the Feign Client

If we want to set it across feign clients, we can configure default settings using following configuration:

application.yml - Default Feign client configuration
feign:
  client:
    config:
      default:  (1)
        connectTimeout: 5000
        readTimeout: 5000
        loggerLevel: basic
1 This setting will be used as default settings across feign clients.

Using Java Configuration

We can achieve the same thing using Java Configuration, all we need to do is to create a Configuration with Bean of type Logger.Level

FeignConfig.kt
@Configuration
class FeignConfig {

    @Bean
    fun feignLoggerLevel(): Logger.Level {
        return Logger.Level.FULL
    }
}

Now we can use the feign config in Feign Client annotation, as show below.

FooClient.kt
@FeignClient(value = "foo-client", url = "http://foo-bar.url", configuration = [FeignConfig::class])
interface FooClient {

    @RequestMapping(method = RequestMethod.GET, value = "/user")
    fun getAllUsers(): List<User>

}

Top articles in this category:
  1. Feign common headers using RequestInterceptor
  2. Feign exception handling in Spring Cloud
  3. Retrofit vs Feign for Server Side
  4. SendGrid emails with Spring Boot and Java
  5. Spring Boot 2.0 Reactive Web Performance Metrics
  6. Setting a Random Port in Spring Boot Application at startup
  7. Custom banner in spring boot


Find more on this topic:
Spring Framework image
Spring Framework

Spring Framework - MVC, Dependency Injection, Spring Hibernate, Spring Data JPA, Spring Boot and Spring Cloud for Microservices Architecture.

Last updated 1 week ago


Recommended books for interview preparation:

This website uses cookies to ensure you get the best experience on our website. more info