Skip to content

Instantly share code, notes, and snippets.

@mpjura mpjura/debug-console.js
Last active Aug 29, 2015

Embed
What would you like to do?
Overwrite console to only run when debug conditions are met
(function( window ){
var console = window.console;
var methods = ["log","dir"],
old = {};
//TODO - set this via query param or whatever you want
var debug = true;
for ( var i = 0, len = methods.length; i < len; i++ ) {
old[ methods[i] ] = console[ methods[i] ];
console[ methods[i] ] = function(){
if ( !debug ){ return; }
old[ methods[i] ].apply( console, [].slice.call( arguments, 0 ) );
}
}
})( this );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.