spring-cloud-netflix: Feign Logging Configuration Not Working As Documented

Based on the Spring Cloud documentation for Feign Logging, I can’t seem to get the Feign logging to work.

Using an example from one of the @joshlong’s great talks, I have the following Reservation Client with a Feign client called com.example.ReservationReader:

package com.example;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.hateoas.Resources;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.stream.Collectors;

@SpringBootApplication
@EnableDiscoveryClient
@EnableZuulProxy
@EnableCircuitBreaker
@EnableFeignClients
public class ReservationClientApplication {
  public static void main(String[] args) {
    SpringApplication.run(ReservationClientApplication.class, args);
  }
}

@FeignClient("reservation-service")
interface ReservationReader {
  @RequestMapping(method = RequestMethod.GET, value = "/reservations")
  Resources<Reservation> read();
}

@RestController
@RequestMapping("/reservations")
class ReservationApiGatewayRestController {

  private final ReservationReader reservationReader;

  public ReservationApiGatewayRestController(ReservationReader reservationReader) {
    this.reservationReader = reservationReader;
  }

  public Collection<String> fallback() {
    return new ArrayList<>();
  }

  @GetMapping("/names")
  @HystrixCommand(fallbackMethod = "fallback")
  public Collection<String> names() {

    return reservationReader.read()
        .getContent()
        .stream()
        .map(Reservation::getReservationName)
        .collect(Collectors.toList());
  }
}

class Reservation {

  private String reservationName;

  public String getReservationName() {
    return reservationName;
  }

  public void setReservationName(String reservationName) {
    this.reservationName = reservationName;
  }
}

And I’ve configured my Config Server to customize the logging level for the Feign Client with this full package name: com.example.ReservationReader. Here’s an Httpie output showing the config is available to the Reservation Client:

$ http localhost:8888/reservation-client/default
HTTP/1.1 200 
Content-Type: application/json;charset=UTF-8
Date: Sat, 11 Mar 2017 01:18:38 GMT
Transfer-Encoding: chunked
X-Application-Context: application:8888

{
    "label": "master",
    "name": "reservation-client",
    "profiles": [
        "default"
    ],
    "propertySources": [
        {
            "name": "/Users/me/repos/joshlong@github/bootiful-microservices-config/reservation-client.properties",
            "source": {
                "logging.level.com.example.ReservationReader": "BASIC",
                "security.oauth2.resource.userInfoUri": "http://localhost:9191/uaa/user",
                "server.port": "${PORT:9999}",
                "spring.cloud.stream.bindings.output.destination": "reservations"
            }
        },
        {
            "name": "/Users/me/repos/joshlong@github/bootiful-microservices-config/application.properties",
            "source": {
                "debug": "true",
                "endpoints.jmx.enabled": "false",
                "endpoints.shutdown.enabled": "true",
                "info.id": "${spring.application.name}",
                "logging.level.com.netflix.discovery": "OFF",
                "logging.level.com.netflix.eureka": "OFF",
                "logging.level.org.springframework.security": "DEBUG",
                "management.security.enabled": "false",
                "spring.jmx.enabled": "false",
                "spring.jpa.generate-ddl": "true",
                "spring.sleuth.log.json.enabled": "true",
                "spring.sleuth.sampler.percentage": "1.0"
            }
        }
    ],
    "state": null,
    "version": "a94a2253c15878304e95995a858f3336545a15ea"
}

And I’ve restarted all of the services several times, so the Reservation Client should have the latest config.

Yet, when I execute a call to the Reservation Client such as: GET http://localhost:9999/reservations/names, nothing is written to the log. How does one properly enable logging of the Feign Client requests? Or is this a bug?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 22 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@fabritma @pluttrell @khannedy Here goes the sample. https://github.com/itmuch/spring-cloud-docker-microservice-book-code/tree/master/microservice-consumer-movie-feign-logging I use Camden SR4 and it WORKS. YOU must follow these two steps:

  1. Write the configuration class:

    @Configuration
    public class FeignLogConfiguration {
      @Bean
      Logger.Level feignLoggerLevel() {
        return Logger.Level.BASIC;
      }
    }
    
  2. Config the feign client’s log level to DEBUG:

    logging:
      level:
        com.itmuch.cloud.study.user.feign.UserFeignClient: DEBUG 
    

Logging seems to still be broken in 2021.

After I added in the configuration in addition to the things above:

@Bean
public Logger logger() {
    return new Slf4jLogger(MyFeignClient.class);
}

it worked for me. Just adding a Slf4jLogger without class did not worked.

hi, i just met the same thing. @spencergibb Feign client:

@FeignClient(name = "kubo", configuration = KuboConfiguration.class)
public interface KuboClient {
    @RequestMapping(value = "/kubo", method = RequestMethod.GET)
    String kubo();
} 

and KuboConfiguration class:

@Configuration
public class KuboConfiguration {
     @Bean
     Logger.Level feignLoggerLevel() {
          return Logger.Level.FULL;
     }
}

when i start the application and come out this log:

2017-04-01 14:17:28.889 ERROR 20559 — [ main] o.s.cloud.logging.LoggingRebinder : Cannot set level: FULL for ‘com.sina.necomaker.gilgamesh.client.foo.feign.KuboClient’

and i also config the logging level in the config server. it also does not work, nothing is written to the log

project address: https://github.com/gilgameshs/gilgamsh-spring-cloud-netflix

Hello there,

I actually have the same issue. Can you please create an example project where feign logging is working. I guess it would help many people 😃