question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feign Logging Configuration Not Working As Documented

See original GitHub issue

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?

Issue Analytics

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

github_iconTop GitHub Comments

18reactions
eacdycommented, May 10, 2017

@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 
    
7reactions
ryandanielspmccommented, May 17, 2021

Logging seems to still be broken in 2021.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feign logging not working - Stack Overflow
You need to configure logging in application.properties as below: logging.level.<package path>.MyClient=DEBUG. If you're using application.yml then:
Read more >
Feign logging - Spring Cloud OpenFeign
This project provides OpenFeign integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring ...
Read more >
Feign Logging Configuration - Baeldung
In this tutorial, we'll describe how we can enable Feign client logging in our Spring Boot application.
Read more >
Feign Client Logging - Apps Developer Blog
Configure Feign Logger Level · BASIC , Log only the request method and URL and the response status code and execution time. ·...
Read more >
Error Decoding and Retrying with Feign Clients
Introduction · Setting up dependencies · Enable feign clients and define a feign client · Enabling logging for feign client · Error Decoder...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found