Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feign Logging Configuration Not Working As Documented #1769

Closed
pluttrell opened this issue Mar 11, 2017 · 22 comments
Closed

Feign Logging Configuration Not Working As Documented #1769

pluttrell opened this issue Mar 11, 2017 · 22 comments

Comments

@pluttrell
Copy link

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?

@khannedy
Copy link
Contributor

+1

@ryanjbaxter
Copy link
Contributor

Can you provide the projects? What version of Spring Cloud?

@pluttrell
Copy link
Author

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.

@spencergibb
Copy link
Member

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.

@pluttrell
Copy link
Author

@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

@spencergibb
Copy link
Member

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;
    }
}

@pluttrell
Copy link
Author

@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.

@gilgameshs
Copy link

gilgameshs commented Apr 1, 2017

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

@spencergibb
Copy link
Member

@fabritma
Copy link

fabritma commented May 8, 2017

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 :)

@eacdy
Copy link
Contributor

eacdy commented 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 
    

@pengisgood
Copy link

@eacdy still doesn't work for me. No log output.

@kylewu
Copy link

kylewu commented Sep 5, 2017

@pengisgood could you provide your config/code so that others can help you

@pengisgood
Copy link

@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);
}

@p3t
Copy link

p3t commented Dec 21, 2017

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.

@onnoweb
Copy link

onnoweb commented Jan 24, 2018

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:

  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)

@spencergibb
Copy link
Member

Triple backticks.

What version?

@onnoweb
Copy link

onnoweb commented Jan 24, 2018

DALSTON.SR4 and spring boot 1.5.8.

@spencergibb
Copy link
Member

If you can provide a minimal sample project that recreates the problem and you think there is a bug, please submit a new issue.

@kelumv
Copy link

kelumv commented Jul 5, 2018

had to do following to work

 @Bean
    Logger.Level feignLoggerLevel(@Value("${feign.client.config.default.loggerLevel: NONE}") String debugLevel) {
        return Logger.Level.valueOf(debugLevel);
    } 

gberche-orange added a commit to orange-cloudfoundry/cf-ops-automation-broker that referenced this issue Apr 23, 2021
@ryandanielspmc
Copy link

Logging seems to still be broken in 2021.

@namsoo2
Copy link

namsoo2 commented Dec 29, 2021

feign.client.default-to-properties value will help you configure if you adjust loggerLevel in code and yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests