Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node console.log truncates output by default. How can I see the full output? [duplicate]

Node's console.log seems to truncate output by default, eg, looking at the output from an API:

{ '@': { xmlns: 'http://ec2.amazonaws.com/doc/2012-03-01/' },    requestId: '123456',    reservationSet:     { item:        { reservationId: 'r-123456',        ownerId: '123456',        groupSet: [Object],        instancesSet: [Object],        requesterId: '123456' } } } 

As you can see, [object] isn't expanded. I guess this is a convenience measure - a lot of people wouldn't want node spewing thousands of lines by default. Is there a way I can tell it to expand the logged item's contents?

like image 714
mikemaccana Avatar asked Aug 02 '12 09:08

mikemaccana


People also ask

How do you check the output of a console log?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.

What is the difference between console log and console dir?

The main difference between these two methods is that the console. log() method displays the “toString” representation of any object passed to it. Whereas, the console. dir() method displays an interactive list of the properties of the specified JavaScript object.

Is node console log synchronous?

Console. log is asynchronous in windows while it is synchronous in linux/mac. To make console. log synchronous in windows write this line at the start of your code probably in index.


1 Answers

There is no option to change console.log, however you can use a function in the bundled util library, util.inspect which does accept a depth parameter. Eg:

 console.log(require('util').inspect(obj, true, 10)); // 10 levels deep 
like image 140
Dan Smith Avatar answered Sep 17 '22 16:09

Dan Smith