I'm trying to get logging working for each request from a Feign rest client. However I cannot get the logging to work, while 'standard' Slf4j logging does work.
I have the following:
public MyClient() {
initConnectionProperties();
this.service = Feign.builder()
.contract(new JAXRSContract())
.decoder(getJacksonDecoder())
.encoder(getJacksonEncoder())
.requestInterceptor(new BasicAuthRequestInterceptor(user, password))
//.client(new OkHttpClient())
.logger(new Slf4jLogger(MyClient.class)) //not working
.logLevel(feign.Logger.Level.BASIC)
.target(MyClient.class, this.url);
logger.info("Connection parameters: url = " + url + ", user = " + user); //Is working
}
You may also need to configure your log4j logging level for
feign
to DEBUG. If you are using spring boot, what worked for me is:First you need to set the logging level for your feign client class to DEBUG, as Maverick already mentioned in his answer.
Then if you use Spring Boot, beside the option to create @Configuration classes as Niraj already mentioned in his answer, you can configure each client individually in you application properties/yml config file:
feign: client: config: the_name_of_your_feign_client: connectTimeout: 5000 readTimeout: 5000 loggerLevel: basic
Or use default instead of the_name_of_your_feign_client to configure all your feign clients in the same way:
feign: client: config: default: connectTimeout: 5000 readTimeout: 5000 loggerLevel: basic
This is how i was able to log using Custom Config class
Note Feign logging only responds to the DEBUG level.
Config Class
Client
application.properties
You need to configure logging in application.properties as below:
If you're using application.yml then:
The log level can be set to tell Feign how much to log.
Options are:
Example:
For more details, you can refer this
I hadn't set a client, and my client calls were failing, and logging wasn't working.. once I added OkHttpClient and changed logback.xml file, worked fine
this is logback.xml