Posted By

brandonjp on 09/12/15


Tagged

debug error console log warn


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

brandonjp


JS - debug console log logger error, warn, info, log, debug


 / Published in: JavaScript
 

// create a variable to toggle debugging // to use it, just call debug(with,any,optional,parameters) debug(x,y,z); // it will try to guess what type of message to log, or you can specify in the first parameter debug("error",x,y,z);

  1. // create a variable to toggle debugging
  2. var debugMode = true;
  3. function debug() {
  4. if (debugMode===true) {
  5. var x = "debug", a = arguments.length ? arguments : ["debug"];
  6. var c = ["error","warn","info","log","debug"];
  7. var t = c.some ? (c.some(function(v) { return x = (a[0].indexOf(v)>-1) ? v : false; }))||x : x;
  8. return console[(x||t)](arguments);
  9. }
  10. }

Report this snippet  

You need to login to post a comment.