Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update doc/api/util.md
  • Loading branch information
bmeck authored Jun 12, 2020
commit 8e6ea1d90218038ea6b385a3de0fe7405811a97e
23 changes: 7 additions & 16 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,18 @@ 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.
The optional `callback` argument can be used to replace the logging function
with a different function that doesn't have any initialization or
unnecessary wrapping.

```js
const util = require('util');
let makeInternalsPublic = false;
Comment thread
bmeck marked this conversation as resolved.
Outdated
const debug = util.debuglog('internals', (debug) => {
makeInternalsPublic = debug !== null;
const debuglog = util.debuglog('internals', (debug) => {
Comment thread
bmeck marked this conversation as resolved.
Outdated
// replace with a logging function that optimizes out
Comment thread
bmeck marked this conversation as resolved.
Outdated
// testing if the section is enabled
debuglog = debug;
});
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])`
Expand Down