Skip to content

Instantly share code, notes, and snippets.

@devinrhode2
Last active December 11, 2015 13:59
Show Gist options
  • Save devinrhode2/4611419 to your computer and use it in GitHub Desktop.
Save devinrhode2/4611419 to your computer and use it in GitHub Desktop.
//Superseeded: https://gist.github.com/devinrhode2/4705947
/**
* Keep a histroy array of console log's
* See example at bottom
*/
window.originalConsole = window.console;
window.originalLog = window.console.log;
window.logWithHistory = function logWithHistoryFn() {
var args = [].slice.call(arguments, 0);
//we could stringify when needed for cpu efficiency, or stringify now for memory efficiency.
logWithHistory.history.push(args);
originalLog.apply(originalConsole, args);
};
logWithHistory.history = [];
window.consoleLogWithHistory = (function(){
var withHistory = {}
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info',/* 'log', */
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
for (var i = 0, l = methods.length; i < l; i++) {
withHistory[methods[i]] = console[methods[i]];
};
withHistory.log = window.logWithHistory;
return withHistory;
})();
/**
* Example
*/
console.log('you can click through to this log');
(function(){
// Set all console.log's to go into history
var console = consoleLogWithHistory;
console.log('no click through, but with history');
})();
console.log('click through');
//Or alias logWithHistory to window.log and call that
window.log = logWithHistory;
log('no click through');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment