当我不调试时,如何禁用console.log? [英] How do I disable console.log when I am not debugging?
问题描述
我的代码中有很多 console.log
(或任何其他控制台调用),我只想使用
当我的应用程序处于某种调试模式时。
I have many console.log
(or any other console calls) in my code and I would like to use them only
when my app is in some kind of "debug mode".
我似乎不能使用某种记录器功能,内部使用 console.log
,因为我会不知道是什么行了。也许只有一个try / catch,但我的日志是非常一般的,我不想在我的代码try / catch。
I can't seem to use some kind of logger function and internally use console.log
because then I wouldn't know what line fired it. Maybe only with a try/catch, but my logs are very general and I don't want try/catch in my code.
你会推荐什么?
推荐答案
我只是使用 GULP (并推荐大家,这是一个了不起的工具),而且我安装了一个名为 stripDebug 为你做的。
Nowdays, in 2014, I simply use GULP (and recommend everyone to, it's an amazing tool), and I have a package installed which is called stripDebug which does that for you.
(我也在生产中使用 uglify
和 closureCompiler
)
(I also use uglify
and closureCompiler
in production)
这篇关于当我不调试时,如何禁用console.log?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!