Skip to content

Commit

Permalink
doc: util.debuglog callback
Browse files Browse the repository at this point in the history
PR-URL: #33856
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bmeck authored and addaleax committed Sep 22, 2020
1 parent 0507535 commit a7a564b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,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 @@ -121,6 +123,19 @@ 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 replace the logging function
with a different function that doesn't have any initialization or
unnecessary wrapping.

```js
const util = require('util');
let debuglog = util.debuglog('internals', (debug) => {
// Replace with a logging function that optimizes out
// testing if the section is enabled
debuglog = debug;
});
```

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

0 comments on commit a7a564b

Please sign in to comment.