How to quickly and conveniently disable all console.log statements in my code?

后端 未结 28 2200
深忆病人
深忆病人 2020-11-22 16:48

Is there any way to turn off all console.log statements in my JavaScript code, for testing purposes?

28条回答
  •  清酒与你
    2020-11-22 17:34

    A simplification of https://stackoverflow.com/a/46189791/871166

    switch (process.env.LOG_LEVEL) {
      case 'ERROR':
        console.warn = function() {};
      case 'WARN':
        console.info = function() {};
      case 'INFO':
        console.log = function() {};
      case 'LOG':
        console.debug = function() {};
        console.dir = function() {};
    }
    
    

提交回复
热议问题