Return to Snippet

Revision: 69810
at September 12, 2015 06:43 by brandonjp


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

Initial URL

                                

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

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

Initial Tags
debug, error, log

Initial Language
JavaScript