Feign Logging Configuration Not Working As Documented
See original GitHub issueBased 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?
Issue Analytics
- State:
- Created 7 years ago
- Comments:22 (8 by maintainers)
@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:
Write the configuration class:
Config the feign client’s log level to DEBUG:
Logging seems to still be broken in 2021.