Improve and document debug options

- Don't look up `process.env.NODE_DEBUG` every time `debug` function is called (regression of b85bf633)
- Add tests and documentation

Closes #892.