Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feign logging not working

Tags:

java

feign

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     } 
like image 728
Magick Avatar asked Mar 12 '17 18:03

Magick


2 Answers

You need to configure logging in application.properties as below:

logging.level.<package path>.MyClient=DEBUG 

If you're using application.yml then:

logging.level.<package path>.MyClient: DEBUG 

The log level can be set to tell Feign how much to log.

Options are:

  • NONE, No logging (DEFAULT)
  • 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

Example:

logLevel(feign.Logger.Level.NONE) or logLevel(feign.Logger.Level.BASIC) or logLevel(feign.Logger.Level.HEADERS) or logLevel(feign.Logger.Level.FULL) 

For more details, you can refer this

like image 174
Maverick Avatar answered Sep 18 '22 12:09

Maverick


This is how i was able to log using Custom Config class

Note Feign logging only responds to the DEBUG level.

Config Class

@Configuration public class UserClientConfig {      @Bean     Logger.Level feignLoggerLevel() {         return Logger.Level.HEADERS;     } }  

Client

@FeignClient(name = "User", url = "http://localhost:8080",configuration=UserClientConfig.class) public interface UserClient {      @RequestMapping(method = RequestMethod.GET, value = "/user")     List<User> getAllUsers();      } 

application.properties

logging.level.<pcakgepath>.UserClient: DEBUG 
like image 36
Niraj Sonawane Avatar answered Sep 17 '22 12:09

Niraj Sonawane