【问题标题】:log http traffic in spring boot web application在 Spring Boot Web 应用程序中记录 http 流量
【发布时间】:2015-01-30 16:51:51
【问题描述】:

我在 tomcat7 上安装了一个 Spring Boot Web 应用程序。我正在寻找一种记录 http 传入和传出请求(标头和正文)的方法。我正在寻找类似于 org.apache.cxf.interceptor.LoggingOutInterceptor 的东西。 你能帮忙吗?

【问题讨论】:

  • 您想记录每个 Http 请求和每个 Http 响应,还是通过登录/注销、特殊请求映射等将它们分开?
  • 使用AbstractRequestLoggingFilter 子类之一来记录请求。您指向的拦截器用于 Web 服务(如果我没记错的话)。如果要为 Spring Web Services 启用日志记录,可以将 org.springframework.ws.client.MessageTracing 设置为跟踪。
  • @s.kwiotek 每个请求/响应
  • @M. Deinum 感谢您提供信息。AbstractRequestLoggingFilter 为请求完成了工作。我需要类似的服务器响应。

标签: spring http logging


【解决方案1】:

您可以实现自己的过滤器,例如:

@Component
public class SimpleFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        HttpServletRequest request = (HttpServletRequest) req;
        // logic...
        chain.doFilter(req, res);
    }

    public void init(FilterConfig filterConfig) {}

    public void destroy() {}

}

这对于你拦截请求和响应的需求也是一个很好的解决方案......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2018-10-26
    • 2018-10-17
    • 2019-06-06
    • 1970-01-01
    相关资源
    最近更新 更多