Here are the steps to log to a log file and configure globally
to log both request and response details for all the tests
create static printstream object
private static PrintStream logps;
try {
// fileoutputstream can be opened in append mode to append the logs every time
// we run
// printstream is enabled for autoflush
logps = new PrintStream(new FileOutputStream("src/test/resources/logfile.txt", true), true);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
In beforeall static method, apply the default implemented request and response logging filters and enable them to use print stream
RestAssured.filters(new RequestLoggingFilter(logps), new ResponseLoggingFilter(logps));
Now we need not specify log() method individually for requests and responses and also the logs will be sent to the log file