Skip to content

Instantly share code, notes, and snippets.

@tweinfeld
Last active May 28, 2016 15:48
Show Gist options
  • Save tweinfeld/825a45a380cb53f5b4d160d4767ea6ba to your computer and use it in GitHub Desktop.
Save tweinfeld/825a45a380cb53f5b4d160d4767ea6ba to your computer and use it in GitHub Desktop.
function createLogger(writer = console.log.bind(console), bufferThreshold = 100, delay = 5000){
let buf = [], timer;
const dispose = ()=>{ writer(buf.splice(0)); };
return function(obj){
buf.push(obj);
clearTimeout(timer);
(buf.length >= bufferThreshold ? dispose() : timer = setTimeout(dispose, delay));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment