Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: util.debuglog callback #33856

Closed
wants to merge 7 commits into from
Closed
Changes from all 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
17 changes: 16 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
jasnell marked this conversation as resolved.
Show resolved Hide resolved
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,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