If you are using Node.js, then debug is extremely efficient as an alternative to console.log ()
This will basically replace console.log (), except that you can enable it on the command line with the DEBUG environment variable based on how you initialized it in each file.
Let's say I have a project with several files specified in the index.js file:
one.js
var debug = require('debug')('one-one'); var func = function() { debug('func'); }
two.js
var debug = require('debug')('one-two'); var func = function() { debug('func'); }
You initialized debugging with the name one-one in the first file and one-two in the second file.
On the command line, I can run them as follows:
node index.js
Result: no debug output. However, if I run it as follows:
DEBUG=* node index.js
Both debug statements will be recorded, however, in different colors and with the name of the debug (one-one or one-two), so I can indicate which file they came from.
Now let's say you want to narrow it down a bit. You can run:
DEBUG = * - two node index.js
To get the debug result that was set with "-two" at the end of the name or
DEBUG = one - * node index.js
so that it all starts with the “one” -
You can also say that you want everything, or a lot of things, or exclude templates or sets. To exclude something that is preceded by a dash, an example:
DEBUG = one *, monkey *, - monkey: banana, -element, -chimp: * node index.js
This will include everything from “one” or “monkey” and exclude everything called “monkey: banana” or “elephant”, or start with “chimpanzee:”
If you want to exclude everything except the following:
DEBUG = *, - pattern1, -pattern2 node index.js