Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a7a564b

Browse filesBrowse files
bmeckaddaleax
authored andcommitted
doc: util.debuglog callback
PR-URL: #33856 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 0507535 commit a7a564b
Copy full SHA for a7a564b

File tree

Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/util.md‎

Copy file name to clipboardExpand all lines: doc/api/util.md
+16-1Lines changed: 16 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.