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

后端 未结 28 2501
深忆病人
深忆病人 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:27

    Ive been using the following to deal with he problem:-

    var debug = 1;
    var logger = function(a,b){ if ( debug == 1 ) console.log(a, b || "");};
    

    Set debug to 1 to enable debugging. Then use the logger function when outputting debug text. It's also set up to accept two parameters.

    So, instead of

    console.log("my","log");
    

    use

    logger("my","log");
    

提交回复
热议问题