logging.level.package-path.FooClient: DEBUG
Feign Client Logging and connection timeout
Upasana | July 14, 2020 | 2 min read | 2,830 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.
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.
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:
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
@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.
@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:
- Feign exception handling in Spring Cloud
- Feign RequestInterceptor in Spring Boot
- Retrofit vs Feign for Server Side
- How does Session handling works in Servlet environment
- Invoking AWS Lambda from a Java Client
- Java 8 date time JSON formatting with Jackson
- Disable SSL verification in Spring WebClient