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


/ Published in: JavaScript
Save to your folder(s)

// 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);


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.