Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,15 @@ callbackFunction((err, ret) => {
});
```

## `util.debuglog(section)`
## `util.debuglog(section[, callback])`
<!-- YAML
added: v0.11.3
-->

* `section` {string} A string identifying the portion of the application for
which the `debuglog` function is being created.
* `callback` {Function} A callback invoked the first time the logging function
is called with a function argument that is a more optimized logging function.
* Returns: {Function} The logging function

The `util.debuglog()` method is used to create a function that conditionally
Expand Down Expand Up @@ -119,6 +121,29 @@ FOO-BAR 3257: hi there, it's foo-bar [2333]
Multiple comma-separated `section` names may be specified in the `NODE_DEBUG`
environment variable: `NODE_DEBUG=fs,net,tls`.

The optional `callback` argument can be used to perform logic depending on if
a section is enabled.

```js
const util = require('util');
let makeInternalsPublic = false;
const debug = util.debuglog('internals', (debug) => {
makeInternalsPublic = debug !== null;
});
let counter = 1;
debug('exposing internals, do not use them as a public API');
module.exports = {
internal: makeInternalsPublic ? {
setCounter(newValue) {
counter = newValue;
}
} : null,
nextValue() {
return counter++;
}
};
```

## `util.deprecate(fn, msg[, code])`
<!-- YAML
added: v0.8.0
Expand Down