I am writing code in modules, and each module can be debugged individually. I want to turn on or off console.log messages on a module level, to focus on just the module I’m working on.
I could have a _debug_ variable for each module set to true or false, and write log messages like
if(_debug_) {
console.log('The is a debug message.');
}
I find this approach a little cumbersome. Can I do better?
You can hijack the
consoleobject upon entering the module scope if you want to disable debug statements. Here’s a simple way to generate a substitute “console” object:Then, at the beginning of the module:
That’s it.