Skip to content

Commit 8dd8b1a

Browse files
bmeckMylesBorins
authored andcommitted
doc: util.debuglog callback
PR-URL: #33856 Reviewed-By: James M Snell <[email protected]>
1 parent 440642d commit 8dd8b1a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

doc/api/util.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ callbackFunction((err, ret) => {
7070
});
7171
```
7272

73-
## `util.debuglog(section)`
73+
## `util.debuglog(section[, callback])`
7474
<!-- YAML
7575
added: v0.11.3
7676
-->
7777

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

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

126+
The optional `callback` argument can be used to replace the logging function
127+
with a different function that doesn't have any initialization or
128+
unnecessary wrapping.
129+
130+
```js
131+
const util = require('util');
132+
let debuglog = util.debuglog('internals', (debug) => {
133+
// Replace with a logging function that optimizes out
134+
// testing if the section is enabled
135+
debuglog = debug;
136+
});
137+
```
138+
124139
## `util.deprecate(fn, msg[, code])`
125140
<!-- YAML
126141
added: v0.8.0

0 commit comments

Comments
 (0)