From 8dd8b1a8be1a2421ed4b166484841a78229a57ca Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 12 Jun 2020 09:20:48 -0500 Subject: [PATCH] doc: util.debuglog callback PR-URL: https://github.com/nodejs/node/pull/33856 Reviewed-By: James M Snell --- doc/api/util.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/doc/api/util.md b/doc/api/util.md index 3887de8e38991e..f21f957bba3eeb 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -70,13 +70,15 @@ callbackFunction((err, ret) => { }); ``` -## `util.debuglog(section)` +## `util.debuglog(section[, callback])` * `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 @@ -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])`