Overwrite the console
block console events for production environments
by amindunited
JavaScript
var LOG_ENV = "dev";
//we can create any alternative "console" name we want:
//(we just have to include it in the if below as well)
window.dbg = window.console;
//Kill all "consoles" if not in dev env
if (LOG_ENV !== "dev") {
window.dbg = window.console = {
debug: function(){},
dir: function(){},
error: function(){},
group: function(){},
groupCollapsed: function(){},
groupEnd: function(){},
info: function(){},
log: function(){},
time: function(){},
timeEnd: function(){},
trace: function(){},
warn: function(){}
};
};
//
var tickCount = 0;
var maxTicks = 5;
var tick = window.setInterval(function(){
/*
//Uncomment to test console.log
if (tickCount >= maxTicks) {
window.clearInterval(tick)
} else {
tickCount++;
console.log("tickCount = ", tickCount);
}
*/
//Uncomment to test dbg
if (tickCount >= maxTicks) {
window.clearInterval(tick)
} else {
tickCount++;
dbg.log("DBG: tickCount = ", tickCount);
}
//window.clearInterval(tick);//commentout when running tests
}, 200)