Quick delete items in the output log console.log

When the project development, the console often have many forget to remove or comment out the output log. But on the line can not delete it one by one, recently summed up a few Solutions

  Rewrite console.log method, loss of output capacity

The most direct and effective, can be placed in frame with the words vue main.js or the index.html. Multi-page, then you can put in a global js. Disadvantages: Sometimes error trapping is to print out the results has also been blocked.

console.log = function () {};

  Improved version

var log = console.log; // 不屏蔽
var log1 = function () {}; // 屏蔽
console.log = function () {
  if(arguments[0] instanceof Error){
    log(...arguments);
  }else{
    log1(...arguments);
  }
}

  The latter development could consider the following design.

When developed, the first log console.log assigned to variables for later use when a log output, when on the line just to function can be rewritten into a log of empty function. And still on the line to be printed as output console.log. This can have the shield and outputs the selected

var log = console.log; // usually develop with this, simple wording, when the replacement line to the next line to shut off 
// var log = function () { }; // this shield into the upper output line 

// e.g. : 
log ( "temporarily print using this function, simple wording, but also to block out late, no longer afraid of my mother forgot to remove the print log"); 
console.log ( "do not want to shield output, such as error and other trapped");

  

Guess you like

Origin www.cnblogs.com/zhaodesheng/p/11442869.html