Skip to content

Instantly share code, notes, and snippets.

@girasquid
Last active December 18, 2015 18:49
Show Gist options
  • Save girasquid/5828228 to your computer and use it in GitHub Desktop.
Save girasquid/5828228 to your computer and use it in GitHub Desktop.
// This helper function lets you make sure that if you're in a situation with a lot of log statements (like inside a loop),
// you'll only see a maximum of MAXIMUM_DUPLICATE_LOG_MESSAGES with the same message before they're quietly discarded.
// (I find it helps with debugging)
var counts = {}
var MAXIMUM_DUPLICATE_LOG_MESSAGES = 10;
function log(message) {
if(counts.hasOwnProperty(message)) {
counts[message]++;
} else {
counts[message] = 0;
}
if(counts[message] < MAXIMUM_DUPLICATE_LOG_MESSAGES) {
console.log(message);
}
}
function clear_log() {
counts = {};
console.clear();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment