title: How to log each request to a csv file
body: <p>I am developing a REST API and I want to write all the calls to a csv file . So I use the <a href="http://opencsv.sourceforge.net/" rel="nofollow noreferrer">opencsv</a> library and i wrote the below code:</p>
  
  <pre><code>   CSVWriter writer;
  
     Map&lt;String, Object&gt; resultMap = new HashMap&lt;String, Object&gt;();
  
  @RequestMapping(value="/data",produces={MediaType.APPLICATION_JSON_VALUE},method=RequestMethod.GET)
      public ResponseEntity&lt;Map&lt;String, Object&gt;&gt; getdata(@RequestParam("id")int id,@RequestParam("user")String user) throws IOException{             
              String[] log = new String[1];
              log[0]=id+","+"+user+","+new Timestamp(System.currentTimeMillis())+",";
              writer.writeNext(log);
  
              writer.flushQuietly();
                  //....rest code here 
  
  return new ResponseEntity&lt;Map&lt;String, Object&gt;&gt;(resultMap,HttpStatus.OK);
  
  }
  </code></pre>
  
  <p>But this only prints a few and does not print all the requests to csv.Why does this happen? Any help is appreciated.</p>