You could overwrite 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 console.log
behaviour, i.e. you can add multiple log messages with a single call.
It will push all new console.log
messages to logMessages
array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…