使用 Spring Boot,如何查看 Zuul 的调试信息?

Using Spring Boot, how do I see debug info for Zuul?

我正在尝试在我的 Spring 引导项目中使用 Zuul。

application.properties

server.context-path=/${spring.application.name}
zuul.routes.engine.path=/api/engine/**
zuul.routes.engine.url=${engine.url}

GET 请求有效;然而,Zuul 没有转发我的 POST 请求。我没有看到此处列出的 GETPOST 的任何调试输出:How To Use.

如何为 Zuul 启用 DEBUG 日志记录模式?

设置 属性 zuul.debug.request=true.

Spencer 的回答不适用于当前的 Zuul 版本(Spring Cloud Starter Zuul 1.4.6.RELEASE)。相反,起作用的是将以下日志记录 属性 添加到 application.yml

logging:
  level:
    org:
      springframework:
        cloud:
          netflix: trace

你需要两件事:

  1. zuul.include-debug-header: true 添加到您的 application.yml 文件。
  2. debug=true 添加到您的请求中,例如http://localhost:8080/api/user/1?debug=true

这样您将在响应X-Zuul-Debug-Header中收到调试数据

为了在 Spring 应用程序中记录请求和响应,我成功地使用了 属性:

logging:
  level:
    org:
      apache:
        http:
          wire: debug

我们正在使用

spring-boot-2.3.3.RELEASE 
spring-cloud-netflix-zuul-2.2.4.RELEASE
zuul-core-1.3.1

我加了

zuul:
  include-debug-header: true
  debug.request: true
  debugFilters.disabled: false

到我的 application.yml 文件。

我加了

com.netflix.zuul.context.Debug.setDebugRequest(true);
com.netflix.zuul.context.Debug.setDebugRequestHeadersOnly(true);
com.netflix.zuul.context.Debug.setDebugRouting(true);

我的过滤器的 doFilter() 方法之一:

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)

然后每个请求的响应都包含一个新的 header X-Zuul-Debug-Header 以及 运行 处理该请求的 zuul 过滤器列表。