title: How to log properly http requests with Spring MVC
body: <p>Hello I've been trying to figure out generic way to log http requests in my application, so far no luck, here is how I handle the logging right now i.e:</p>
  
  <pre><code>@RequestMapping(value="register", method = RequestMethod.POST)
      @ResponseBody
      public String register(@RequestParam(value="param1",required=false) String param1, @RequestParam("param2") String param2, @RequestParam("param3") String param3, HttpServletRequest request){
          long start = System.currentTimeMillis();
          logger.info("!--REQUEST START--!");
  
          logger.info("Request URL: " + request.getRequestURL().toString());
  
          List&lt;String&gt; requestParameterNames = Collections.list((Enumeration&lt;String&gt;)request.getParameterNames());
          logger.info("Parameter number: " + requestParameterNames.size()); 
  
   for (String parameterName : requestParameterNames){
             logger.info("Parameter name: " + parameterName + " - Parameter value: " + request.getParameter(parameterName));
          }
                    //Some processing logic, call to the various services/methods with different parameters, response is always String(Json)
          String response = service.callSomeServiceMethods(param1,param2,param3);
  
  logger.info("Response is: " + response);
  
          long end = System.currentTimeMillis();
          logger.info("Requested completed in: " + (end-start) + "ms");
          logger.info("!--REQUEST END--!");   
  
          return response;
      }
  </code></pre>
  
  <p>So what I do right now for different controllers/methods is copy everything from beginning of the inside of the method until the processing logic which differs from method to method and then copy everything from below of that as showed in above template.</p>
  
  <p>It is kind of messy, and there is a lot of code repetition(which I don't like). But I need to log everything.</p>
  
  <p>Does anyone have more experience with this kinds of logging, can anyone shed some light on this?</p>