I'd like to:
- insert debug logging statements into my code that I want to be able to turn on and off during development; and
- then have these statements stripped out entirely in production.
To accomplish stripping out the logs for production, I've seen that the React project itself uses this idiom:
if ("production" !== process.env.NODE_ENV) {
// warn or log or whatever
}
By compiling the modules with process.env.NODE_ENV set to "production" and then running the bundle through a dead code eliminator like UglifyJS, the logs will be eliminated as unreachable.
This is fine, but are there more flexible solutions? I'm thinking something like the debug() Node module, or really some even more powerful, like the Java logging APIs.
I am wondering why I'm not finding a module that combines the ("production" !== process.env.NODE_ENV) approach with debug().
