Last active
December 18, 2015 18:49
-
-
Save girasquid/5828228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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