JSFiddle - React, Tailwind, and code Playground
by SamHasler
JavaScript
var count = 0,counter = function(){};
counter.toString = function f(){
// NB: Chromium Dev tools console.log will call toString twice for some reason.
console.log("COUNT", count, arguments, arguments.callee, "STACK:", (new Error).stack); // , f.caller
return count++;
};
function setDebug(isDebug) {
if (isDebug) {
window.debug = {
log: window.console.log.bind(window.console, counter),
error: window.console.error.bind(window.console, 'error: %s'),
info: window.console.info.bind(window.console, 'info: %s'),
warn: window.console.warn.bind(window.console, 'warn: %s')
};
} else {
var __no_op = function() {};
window.debug = {
log: __no_op,
error: __no_op,
warn: __no_op,
info: __no_op
}
}
}
setDebug(true);
// ...
debug.log('wat', 'Yay custom levels.'); // -> wat: Yay custom levels. (line X)
debug.info('This is info.'); // -> info: This is info. (line Y)
debug.error('Bad stuff happened.'); // -> error: Bad stuff happened. (line Z)
debug.log('wat', 'Yay custom levels.'); // -> wat: Yay custom levels. (line X)
debug.info('This is info.'); // -> info: This is info. (line Y)
debug.error('Bad stuff happened.'); // -> error: Bad stuff happened. (line Z)
//---------------------------------------------------------
// Let's Experiment with console.log and toString:
var nativeConsoleLog = console.log.bind(window.console);
var deLog = function(){
// realLog("Deactivate NO LOG 1");
window.console.log = nativeConsoleLog.bind(window.console);
// realLog("Deactivate NO LOG 2");
};
var noLog = function(){};
noLog.toString = function self(){
/**
* We could force a function like this to be called first whenever
* console.log is called by binding nolog as the first parameter
* to console.log
*
* Can we use this to stop console.log from outputting anything
* i.e. a way to turn standard console.log logging on/off from...