1 # debuglog - backport of util.debuglog() from node v0.11
3 To facilitate using the `util.debuglog()` function that will be available when
4 node v0.12 is released now, this is a copy extracted from the source.
8 Return `util.debuglog`, if it exists, otherwise it will return an internal copy
9 of the implementation from node v0.11.
13 * `section` {String} The section of the program to be debugged
14 * Returns: {Function} The logging function
16 This is used to create a function which conditionally writes to stderr
17 based on the existence of a `NODE_DEBUG` environment variable. If the
18 `section` name appears in that environment variable, then the returned
19 function will be similar to `console.error()`. If not, then the
20 returned function is a no-op.
25 var debuglog = util.debuglog('foo');
28 debuglog('hello from foo [%d]', bar);
31 If this program is run with `NODE_DEBUG=foo` in the environment, then
32 it will output something like:
34 FOO 3245: hello from foo [123]
36 where `3245` is the process id. If it is not run with that
37 environment variable set, then it will not print anything.
39 You may separate multiple `NODE_DEBUG` environment variables with a
40 comma. For example, `NODE_DEBUG=fs,net,tls`.