How to Log HttpRequest and HttpResponse in a file?

前端 未结 2 1259
迷失自我
迷失自我 2020-11-30 13:11

Can anyone explain any techniques to log HttpRequest and HttpResponse in a file.

We are using Spring MVC/Spring Rest.

What we want is to intercept the reques

2条回答
  •  不知归路
    2020-11-30 13:44

    For logging the request Spring has the AbstractRequestLoggingFilter class (well actually one of the subclasses). This can be used to log the incoming request (before and after processing).

    Depending on the configuration this can include the payload, client information and full URL (including erquest parameters). All these three are disabled by default but can be enabled through configuration (see the javadoc for more information).

    
        requestLoggingFilter
        org.springframework.web.filter.CommonsRequestLoggingFilter
        
            includeClientInfo
            true
        
        
            includePayload
            true
        
        
            includeQueryString
            true
        
    
    
    
        requestLoggingFilter
        dispatcherServlet
    
    

    The filter will now log everything using a Commons Logging logger to a logfile.

提交回复
热议问题