I have some console.log commands spread through my site.
Is it possible to override console.log with my own function? I want to customize the function so that it only logs if a specific variable is set to true.
In the end, I would still need to call the real console.log from this function.
Thanks Kevin
Just create a closure, and store the original console.log
function in a local variable.
Then override console.log
, and call the original function after you do your check:
(function(){
var original = console.log;
console.log = function(){
if ( log ) { // <-- some condition
original.apply(this, arguments);
}
};
})();
Here's the fiddle: http://jsfiddle.net/J46w8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With