Is there any way to turn off all console.log
statements in my JavaScript code, for testing purposes?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
I developed a library for this usecase: https://github.com/sunnykgupta/jsLogger
Features:
log
,warn
,error
,info
.Is open for modifications and will be updated whenever new suggestions come up.
I have used winston logger earlier.
Nowadays I am using below simpler code from experience:
Set the environment variable from cmd/ command line (on Windows):
Or, you could have a variable in your code if you like, but above is better.
Restart cmd/ command line, or, IDE/ editor like Netbeans
Have below like code:
Now use all console.* as below:
Now, based on your LOG_LEVEL settings made in the point 1 (like,
setx LOG_LEVEL log
and restart command line), some of the above will print, others won't printHope that helped.
As far as I can tell from the documentation, Firebug doesn't supply any variable to toggle debug state. Instead, wrap console.log() in a wrapper that conditionally calls it, i.e.:
To not have to change all the existing calls, you can use this instead:
I am surprised that of all those answers no one combines:
I'd go for this:
This a hybrid of answers from SolutionYogi and Chris S. It maintains the console.log line numbers and file name. Example jsFiddle.