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

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

    This should override all methods of window.console. You can put it on the very top of your scripts section, and if you are on a PHP framework you can only print this code when your app environment is production, or if some kind of debug flag is disabled. Then you would have all your logs in your code working on development environments or in debug mode.

    window.console = (function(originalConsole){
        var api = {};
        var props = Object.keys(originalConsole);
        for (var i=0; i

提交回复
热议问题