Skip to content

Instantly share code, notes, and snippets.

@selcarpa
Last active January 26, 2022 15:35
Show Gist options
  • Save selcarpa/11f145737af41566646f7d4aed505724 to your computer and use it in GitHub Desktop.
Save selcarpa/11f145737af41566646f7d4aed505724 to your computer and use it in GitHub Desktop.
@Bean
public Client loggedFeignClient(SpringClientFactory springClientFactory) {
return new LoadBalancerFeignClient(new Client.Default(null, null) {
@Override
public Response execute(Request request, Request.Options options) throws IOException {
log.info(
String.format(
"Feign请求开始:\n###\n%s %s\n%s\n\n%s",
request.httpMethod().toString(),
request.url(),
request.headers().keySet().stream().map(
k ->
String.format(
"%s:%s",
k,
String.join(";", request.headers().get(k))))
.collect(Collectors.joining("\n")),
request.requestBody().asString())
);
return super.execute(request, options);
}
}, new CachingSpringLoadBalancerFactory(springClientFactory), springClientFactory);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment