How to disable console.log messages based on criteria from specific javascript source (method, file) or message contents

后端 未结 5 1284
傲寒
傲寒 2020-12-06 07:34

I am working on project that uses quite a few js libraries and one of them is outputting awful lot into console, it is polluting the airwaves so bad that it makes it hard to

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 07:50

    If it's an option to modify file, you can set a flag at top of file for disabling logs for that:

    var DEBUG = false;
    DEBUG && console.log("cyberpunk 2077");
    

    To disable logs for all js files, put it once at top of any js file:

    var DEBUG = false;
    if (!DEBUG) {
       console.log = () => {};
     }
    

提交回复
热议问题