Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS: Where does console.debug output go?

Tags:

node.js

Where does console.debug output go? And how can it be enabled to appear on the stdout, like console.log?

I looked it up in https://nodejs.org/api/console.html, but it does not appear. If, however, I run node from the command line, it is defined.

node
console.debug
[Function: debug]
console.debug('but where does this go?')

So the function is defined, but (by default) doesn't output to stdout or stderr. I'm guessing there is a flag to enable to turn it on.

like image 535
PatS Avatar asked Nov 06 '17 21:11

PatS


People also ask

Where does console log write to?

The console. log() is a function that writes a message to log on the debugging console, such as Webkit or Firebug. In a browser you will not see anything on the screen. It logs a message to a debugging console.

Where do NodeJS logs go?

There is no log file. Each node. js "app" is a separate entity. By default it will log errors to STDERR and output to STDOUT.

How do I check my console debugger?

The console. debug() method outputs a message to the web console at the "debug" log level. The message is only displayed to the user if the console is configured to display debug output. In most cases, the log level is configured within the console UI.

How does NodeJS console log work?

log() function from console class of Node. js is used to display the messages on the console. It prints to stdout with newline. Parameter: This function contains multiple parameters which are to be printed.


1 Answers

Starting with node v8.0.0 and prior to v8.10 and v10.x (depending on the specific method), the global console exposed many of the same methods that are exposed in browsers, but did not document their existence or behavior. Such methods include:

console.debug                 console.dirxml                console.markTimeline
console.profile               console.profileEnd            console.table
console.timeStamp             console.timeline              console.timelineEnd 

The implementation for these methods were not in node (they did not appear in lib/console.js); they were added by V8 itself and were copied onto node's global console object.

As you've observed, calling these methods did not result in anything going to stdout. Instead, output goes to any attached inspectors.

This means you have to run node with the --inspect flag, open Chrome and go to chrome://inspect, then attach the inspector to your process. You will see the output of the extended console methods in the inspector's console.

Keep in mind that by default, the inspector console filters out calls to console.debug. You need to click the levels dropdown and check Verbose in order to see console.debug output.

Alternatively, you could:

  • In node v8.0-8.9, do something like console.debug = console.log if you just want to see output on stdout
  • update to node v8.10

As of v8.10.0, the console.debug method is implemented by node and its output appears on stdout. The GUI inspector retains its behavior (messages are hidden unless you change the logging level).

node v10.x implements many of the other methods listed above, which means these methods are now work as expected (ie show up on stdout) and are documented.

like image 76
josh3736 Avatar answered Sep 28 '22 05:09

josh3736