2

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?

Community
  • 1
  • 1
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51

1 Answers1

3

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.

Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51