节点console.log默认截断输出。如何查看完整输出? [英] Node console.log truncates output by default. How can I see the full output?

查看:438
本文介绍了节点console.log默认截断输出。如何查看完整输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Node的console.log似乎默认截断输出,例如,查看API的输出:

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' } } }

如您所见, [object] 未展开。我想这是一个方便的措施 - 很多人不希望节点默认喷出数千行。有没有办法告诉它扩展记录项目的内容?

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?

推荐答案

没有选项可以更改 console.log ,但是你可以使用捆绑的util库中的函数, util.inspect ,它接受深度参数。例如:

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

这篇关于节点console.log默认截断输出。如何查看完整输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆