Skip to content

Instantly share code, notes, and snippets.

@jgermade
Created October 16, 2014 11:06
Show Gist options
  • Save jgermade/28e7090d654592c99e58 to your computer and use it in GitHub Desktop.
Save jgermade/28e7090d654592c99e58 to your computer and use it in GitHub Desktop.
log.js
(function() {
var log;
log = function(enable) {
if (log.enabled) {
log.history.push(arguments);
if (window.console) {
window.console.log.apply(window.console, Array.prototype.slice.call(arguments));
}
} else if (enable === !void 0) {
log.enabled = enable;
}
};
if(window.console) {
['info', 'warn', 'debug', 'error'].forEach(function (type) {
log[type] = function () {
window.console[type].apply(window.console, Array.prototype.slice.call(arguments));
}
});
}
log.history = [];
log.clear = function() {
log.history = [];
if (window.console) console.clear();
};
window.log = log;
log.enabled = true;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment