【问题标题】:how can I disable console.info messages temporarily in chrome?如何在 Chrome 中暂时禁用 console.info 消息?
【发布时间】:2014-02-28 21:25:08
【问题描述】:

在开发过程中,我的应用程序有很多控制台消息,有没有办法关闭和打开这些消息,而不必一一注释掉?

如果可能的话,用一个变量在模式之间切换,甚至在运行时?

【问题讨论】:

    标签: javascript debugging google-chrome logging console


    【解决方案1】:

    大多数浏览器都在控制台中内置了按级别过滤;这是一个使用 Chrome 的示例

    【讨论】:

      【解决方案2】:

      我编写了这个小技巧,以便能够打开和关闭它(通过使用您的代码更改 window.loggingInfoDisabled 变量来实现)。当然,这也可以用于 .log、.warning 和 .error。

      //能够关闭信息消息的记录 window.loggingInfoDisabled = true;

      window.console.info_old = window.console.info;
      window.console.info = function(myString) {
          if (window.loggingInfoDisabled) {
              //do nothing
          }
          else {
              console.info_old(myString);        
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-08-02
        • 1970-01-01
        • 2017-01-04
        • 1970-01-01
        • 2011-07-03
        • 2011-12-19
        • 2011-01-20
        • 1970-01-01
        相关资源
        最近更新 更多