![]() |
VOOZH | about |
The βutilβ module provides βutilityβ functions that are used for debugging purposes. For accessing those functions we need to call them (by βrequire(βutilβ)β).
The util.debuglog() (Added in v0.11.3) method is an inbuilt application programming interface of the util module which is used to create a function that is based on the NODE_DEBUG environment variable which writes debug messages conditionally to stderr. The returned function operates in the same way as console.error() if the section name appears inside the value of that environment variable. If not, then the returned function is a no-op.
Syntax:
util.debuglog(section[, callback])
Parameters: This function accepts two parameters as mentioned above and described below:
Return Value <Function>: It Returns the logging function.
Example 1: Filename: index.js
Run index.js file using the following command:
SET NODE_DEBUG=run-app*&&node index.js OR NODE_DEBUG=run-app* node index.js
Output:
>> RUN-APP 8112: hello from my debugger [123]
>> RUN-APP1 8112: hello from run-app [123]
>> <ref *1> [Function (anonymous)] {...... [prototype]: { [constructor]: [Circular *1] }
}
>> old Value
>> RUN-APP2 8112:
>> RUN-APP2 8112: hi there, it's run-app [2333]
Example 2: Filename: index.js
Run index.js file using the following command:
SET NODE_DEBUG=alfa-*&&node index.js OR NODE_DEBUG=alfa-* node index.js
Output:
ALFA-BETA 7008: Hii there, debuglog from alfa-beta [2333]
ALFA- 7008: Leaving alfa-...
Wait for timerLog...
ALFA-ROMEO 7008: timer fired after 800
Reference: https://nodejs.org/api/util.html#util_util_debuglog_section_callback