Skip to content

Instantly share code, notes, and snippets.

@ReeMii
Created April 30, 2014 06:59
Show Gist options
  • Select an option

  • Save ReeMii/11419795 to your computer and use it in GitHub Desktop.

Select an option

Save ReeMii/11419795 to your computer and use it in GitHub Desktop.
console.log patch for IE and class _debug or _d to use instead of console.xxx functions. Minimised version included
if (typeof console === "undefined") {
var console = {
log: function() {},
info: function() {} ,
warn: function() {},
error: function() {}
}
}
_debug = {
log : function(message) {
if(!config.debug) { return; }
if(typeof console === 'undefined') { return; }
if(typeof console.log === 'undefined') { return; }
console.log(message);
},
warn : function(message) {
if(!config.debug) { return; }
if(typeof console === 'undefined') { return; }
if(typeof console.warn === 'undefined') { return; }
console.warn(message);
},
info : function(message) {
if(!config.debug) { return; }
if(typeof console === 'undefined') { return; }
if(typeof console.info === 'undefined') { return; }
console.info(message);
},
error : function(message) {
if(!config.debug) { return; }
if(typeof console === 'undefined') { return; }
if(typeof console.error === 'undefined') { return; }
console.error(message);
},
dir : function(obj) {
if(!config.debug) { return; }
if(typeof console === 'undefined') { return; }
if(typeof console.dir === 'undefined') { return; }
console.dir(obj);
},
l : function(message) {
this.log(message);
},
w : function(message) {
this.warn(message);
},
i : function(message) {
this.info(message);
},
e : function(message) {
this.error(message);
},
d : function(obj) {
this.dir(obj);
}
};
_d = _debug;
if (typeof console === "undefined") {var console = {log: function() {}, info: function() {} , warn: function() {}, error: function() {} } } _debug = {log : function(message) {if(!config.debug) { return; } if(typeof console === 'undefined') { return; } if(typeof console.log === 'undefined') { return; } console.log(message); }, warn : function(message) {if(!config.debug) { return; } if(typeof console === 'undefined') { return; } if(typeof console.warn === 'undefined') { return; } console.warn(message); }, info : function(message) {if(!config.debug) { return; } if(typeof console === 'undefined') { return; } if(typeof console.info === 'undefined') { return; } console.info(message); }, error : function(message) {if(!config.debug) { return; } if(typeof console === 'undefined') { return; } if(typeof console.error === 'undefined') { return; } console.error(message); }, dir : function(obj) {if(!config.debug) { return; } if(typeof console === 'undefined') { return; } if(typeof console.dir === 'undefined') { return; } console.dir(obj); }, l : function(message) {this.log(message); }, w : function(message) {this.warn(message); }, i : function(message) {this.info(message); }, e : function(message) {this.error(message); }, d : function(obj) {this.dir(obj); } }; _d = _debug;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment