You can overwrite the console.log method before using it:
var logBackup = console.log; var logMessages = []; console.log = function() { logMessages.push.apply(logMessages, arguments); logBackup.apply(console, arguments); };
Using apply and arguments preserves the correct behavior of console.log , i.e. You can add multiple log messages with a single call.
It will move all new console.log messages to the logMessages array.
Audrius lubys
source share