title: How to configure RestAssured LogConfig to write request and response to a text file
body: <p>I am totally newbie to RestAssured. I like to write the request and response to text file. I do not want to repeat code in each and every test to extract and write Request and Response but instead I like to configure RestAssuredConfig in a setup method to redirect the request and response to text file. </p>
  
  <p>Can someone please help me understand what I am missing in my code? I am trying to configure LogConfig to write request and response to StringWriter so that I can use it to write to a required file? </p>
  
  <p>I tried several examples from google but none helped.</p>
  
  <p>Please note, below example is a proto type in which I am temporarily doing sysout and once the code works I can write it to text file.</p>
  
  <p>//This is a sample code from where I am calling the configure log method //configureRequestLogging</p>
  
  <pre><code>RequestSpecification request = given();
  RequestSpecification logRequest = configureRequestLogging(request);
  </code></pre>
  
  <p>//This method is expected to SOP the request and response. But I am always getting void</p>
  
  <pre><code>private static RequestSpecification configureRequestLogging(RequestSpecification request) {
      RequestSpecification requestSpec;
      final StringWriter writer = new StringWriter();
      PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
      requestSpec = request.config(RestAssuredConfig.config().logConfig(LogConfig.logConfig().defaultStream(captor)))
      .log().all();
  
      System.out.println(writer.toString());
  
      return requestSpec;
      }
  </code></pre>