diff --git a/doc/api/util.md b/doc/api/util.md index b14c5969f0b416..bf4bc0e2f62a0a 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -136,6 +136,42 @@ let debuglog = util.debuglog('internals', (debug) => { }); ``` +### `debuglog().enabled` + + +* {boolean} + +The `util.debuglog().enabled` getter is used to create a test that can be used +in conditionals based on the existence of the `NODE_DEBUG` environment variable. +If the `section` name appears within the value of that environment variable, +then the returned value will be `true`. If not, then the returned value will be +`false`. + +```js +const util = require('util'); +const enabled = util.debuglog('foo').enabled; +if (enabled) { + console.log('hello from foo [%d]', 123); +} +``` + +If this program is run with `NODE_DEBUG=foo` in the environment, then it will +output something like: + +```console +hello from foo [123] +``` + +## `util.debug(section)` + + +Alias for `util.debuglog`. Usage allows for readability of that doesn't imply +logging when only using `util.debuglog().enabled`. + ## `util.deprecate(fn, msg[, code])`