Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between console.log and process._rawDebug

Tags:

node.js

What is the difference between console.log and process._rawDebug?

This answer tells me that console.log actually calls process.stdout.write with formatting and a new line at the end. According to this article process._rawDebug also writes to the terminal but uses process.stderr. I'm not sure how reliable this article is, though.

I logged 10.000 messages (for testing purposes) to the console using console.log and process._rawDebug. The later was at least twice as fast which should mean something I guess.

Are there any dis(advantages) of using console.log or process._rawDebug? Which one is better/safer to use for logging small messages?

like image 675
Thomas Bormans Avatar asked Oct 15 '25 08:10

Thomas Bormans


1 Answers

I have found the answer on the Node 0.x archive repository on Github. The commit message description:

This is useful when we need to push some debugging messages out to stderr, without going through the Writable class, or triggering any kind of nextTick or callback behavior.

The reason why it is faster is because it bypasses JavaScript entirely and the output is logged directly to the terminal.

like image 193
Thomas Bormans Avatar answered Oct 17 '25 03:10

Thomas Bormans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!