trentm/node-bunyan

logging an array restricts the item count

flolege opened this issue · 1 comments

When I log an object via

this.log.info("Info: ", this.myObject)

and myObject contains an array property with multiple items, the output of these items is somehow restricted, it will show me something like

... 40 more items

instead of the rest of the array items.

The logger logs to a rotating file.

How can I change that behaviour to log every item in the array?

@flolege extra trailing args to Bunyan's log.info after a string without formatting %... codes will render vars using util.inspect just like console.log does:

> console.log(a)
[
  'i0',  'i1',  'i2',  'i3',  'i4',  'i5',  'i6',  'i7',
  'i8',  'i9',  'i10', 'i11', 'i12', 'i13', 'i14', 'i15',
  'i16', 'i17', 'i18', 'i19', 'i20', 'i21', 'i22', 'i23',
  'i24', 'i25', 'i26', 'i27', 'i28', 'i29', 'i30', 'i31',
  'i32', 'i33', 'i34', 'i35', 'i36', 'i37', 'i38', 'i39',
  'i40', 'i41', 'i42', 'i43', 'i44', 'i45', 'i46', 'i47',
  'i48', 'i49', 'i50', 'i51', 'i52', 'i53', 'i54', 'i55',
  'i56', 'i57', 'i58', 'i59', 'i60', 'i61', 'i62', 'i63',
  'i64', 'i65', 'i66', 'i67', 'i68', 'i69', 'i70', 'i71',
  'i72', 'i73', 'i74', 'i75', 'i76', 'i77', 'i78', 'i79',
  'i80', 'i81', 'i82', 'i83', 'i84', 'i85', 'i86', 'i87',
  'i88', 'i89', 'i90', 'i91', 'i92', 'i93', 'i94', 'i95',
  'i96', 'i97', 'i98', 'i99',
  ... 400 more items
]

Some ways to print all the array values are:

  1. to format it using the JSON percent code: log.info("my array: %j", a)
{"name":"foo","hostname":"purple.local","pid":62641,"level":30,"msg":"my array: [\"i0\",\"i1\",\"i2\",\"i3\",\"i4\",\"i5\",\"i6\",\"i7\",\"i8\",\"i9\",\"i10\",\"i11\",\"i12\",\"i13\"...
  1. to format it manually to a string: log.info('my array:', JSON.stringify(a));

  2. or put it as a named field in the first arg to log.info: log.info({a: a}, 'my array');:

{"name":"foo","hostname":"purple.local","pid":62660,"level":30,"a":["i0","i1","i2","i3","i4","i5","i6","i7","i8","i9","i10","i11","i12","i13","i14","i15","i16","i17","i18","i19","i20" ...

Depends exactly what you want.