Set restAssured to log all requests and responses globally

Add logging filters to RestAssured defaults, see filters and defaults.

To create a filter you need to implement the io.restassured.filter.Filter interface. To use a filter you can do:
given().filter(new MyFilter()). ..

There are a couple of filters provided by REST Assured that are ready to use:
1. io.restassured.filter.log.RequestLoggingFilter: A filter that'll print the request specification details.
2. io.restassured.filter.log.ResponseLoggingFilter: A filter that'll print the response details if the response matches a given status code.
3. io.restassured.filter.log.ErrorLoggingFilter: A filter that'll print the response body if an error occurred (status code is between 400 and 500)

Any filter could be added to request, spec or global defaults:

RestAssured.filters(..); // List of default filters


I think you need to see the logs then test fails, in this case just use this configuration from rest assured:

RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();


Put this line of code on your @BeforeClass method and every given call will create a log just like using log.all() after every given:

RestAssured.filters(new RequestLoggingFilter(), new ResponseLoggingFilter());


Rest-Assured project:
https://github.com/rest-assured/rest-assured/blob/master/rest-assured/src/main/java/io/restassured/filter/log/RequestLoggingFilter.java