I get over 1 GB logs after each execution of functional tests if DEBUG level is set for all requests using the the following line in the logback-test.xml
:
<logger name="com.intuit.karate" level="DEBUG"/>
And the logs are getting much bigger if gatling performance tests
are executed with DEBUG
level. Setting the DEBUG
level is required to analyze the concurrency problems.
I would like to reduce the logs and log only details on failed requests, but setting just the ERROR
level is not enough, because the failed request and response details are not logged:
<logger name="com.intuit.karate" level="ERROR"/>
Is it possible to configure DEBUG
log level only on failed REST API requests?
What would be the correct way to achieve that?
UPDATE:
Thanks to the answer bellow I ended up with INFO
level in logback-test.xml
:
<logger name="com.intuit.karate" level="INFO"/>
and the following code in karate-config.js
:
// setup global hook to log details only on failed scenarios
karate.configure('afterScenario', function(){
var info = karate.info;
if(info.errorMessage) {
karate.log('failed',info.scenarioType+':',info.scenarioName);
var r = karate.prevRequest;
if(r) {
var log = 'request: ' + r.method + ' ' + r.uri + '\n' + karate.pretty(r.headers)
if(r.body) log += '\n' + r.body
karate.log(log);
karate.log('response: ' + response);
}
}
})
UPDATE 2: found some limitations due to the code reuse (sub-calls). The hook won't log the details in following scenarios:
Scenario: CRUD for a machine group.
When call read('this:create-machinegroup.feature')
Then call read('this:retrieve-machinegroup.feature@last-created')
And call read('this:update-machinegroup.feature')
And call read('this:delete-machinegroup.feature@single')
And call read('this:retrieve-machinegroup.feature@404')