11

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.

2
  • i'd guess you'd be able to see them if you were using the debugger, but i've never messed with it. Commented Nov 6, 2017 at 21:51
  • 2
    Yeah, just tested, those ARE visible in the debugger. @23k Commented Nov 6, 2017 at 21:55

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.