I want to print console error with response code 4xx or 5xx in a logger file while executing automation script in protractor. Now I am using the following code in my afterEach. It prints everything from the console.
browser.manage().logs().get('browser').then(function(browserLog) {
console.log('log: ' + require('util').inspect(browserLog));
});