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?
Comment From: khannedy
+1
Comment From: ryanjbaxter
Can you provide the projects? What version of Spring Cloud?
Comment From: pluttrell
Camden SR6. In terms of the projects, people have so many different preferences and such that I didn't want those to get in the way. Plus you need to have git repo setup for the config.. That's why I provided all of the code.
Comment From: spencergibb
Then provide it as a working project as a zip file please. It's very error prone and time consuming for us to try and copy and paste.
Comment From: pluttrell
@spencergibb Very error prone is an understatement.
Here's a full example with step by step instructions: https://github.com/pluttrell/spring-cloud-feign-logging-not-working
Comment From: spencergibb
If you continue in the documentation you'll see that by default nothing is logged.
You must attatch a configuration to your @FeignClient.
public class FooConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
Comment From: pluttrell
@spencergibb Many thanks for the response. When I read the docs, it appears that we could either set the property or set the level with code (via a @Configuration annotated class). Doing both did enable logging, so I'm closing the issue.
Comment From: gilgameshs
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
Comment From: spencergibb
It's not the same thing.
FULL isn't a valid log level https://github.com/gilgameshs/gilgamesh-config-repo/blob/master/foo.yml#L15
See https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-custom-log-levels
Comment From: fabritma
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 :)
Comment From: eacdy
@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:
@Configuration
public class FeignLogConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.BASIC;
}
}
- Config the feign client's log level to DEBUG:
logging:
level:
com.itmuch.cloud.study.user.feign.UserFeignClient: DEBUG
Comment From: pengisgood
@eacdy still doesn't work for me. No log output.
Comment From: kylewu
@pengisgood could you provide your config/code so that others can help you
Comment From: pengisgood
@kylewu I do have very similar config as @eacdy
In application.yml:
logging:
level:
com.xxx.client.ReservationClient: DEBUG
Configuration bean:
@Configuration
public class LoggingConfiguration {
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
The Feign client:
@FeignClient(name = "xx-reservation", configuration = LoggingConfiguration.class)
public interface ReservationClient {
@RequestMapping(value = "/reservations", method = POST,
consumes = APPLICATION_JSON_VALUE)
ReservationDto createReservation(@RequestBody ReservationDto reservation);
}
Comment From: p3t
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.
Comment From: onnoweb
Following all the steps in the comments above and it still doesn't log for me.
in application.yml:
logging:
level:
com.onno.interfaces.OrganizationFeignClient: DEBUG
feign:
client.config.default.loggerLevel: full
In FeignConfiguration.class:
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
@Bean
public Logger logger() {
return new Slf4jLogger(OrganizationFeignClient.class);
}
And my Feign interface:
@FeignClient(name = "organization-service", configuration = FeignConfiguration.class)
public interface OrganizationFeignClient {```
(apologies for the formatting, I don't seem to be able to get the 'insert code' to work right)
**Comment From: spencergibb**
Triple backticks.
What version?
**Comment From: onnoweb**
DALSTON.SR4 and spring boot 1.5.8.
**Comment From: spencergibb**
If you can provide a minimal sample project that recreates the problem and you think there is a bug, please submit a new issue.
**Comment From: kelumv**
had to do following to work
@Bean Logger.Level feignLoggerLevel(@Value("${feign.client.config.default.loggerLevel: NONE}") String debugLevel) { return Logger.Level.valueOf(debugLevel); }
```
Comment From: ryandanielspmc
Logging seems to still be broken in 2021.
Comment From: namsoo2
feign.client.default-to-properties value will help you configure if you adjust loggerLevel in code and yml