Node console.log truncates output by default. How

2019-03-09 08:25发布

This question already has an answer here:

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?

1条回答
迷人小祖宗
2楼-- · 2019-03-09 08:49

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
查看更多
登录 后发表回答