0

I'm trying to omit this kind of data from a class that inherits from when doing a console.log():

asset: 
   PassThrough {
     filename: 'old_man',
     data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 f0 00 f0 00 00 ff db 00 43 00 05 03 04 04 04 03 05 04 04 04 05 05 05 06 07 0c 08 07 07 07 07 0f 0b 0b 09 ... >,
     originalLocation: '/path/to/lib/image.jpg',
     contentType: [Getter/Setter],
     _readableState: 
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: false,
        endEmitted: false,
        reading: false,

... etc.

Normally I'd try something like:

Object.defineProperty(self, 'PassThrough', {
    configurable: true,
    writable: true,
    enumerable: false
})

But because PassThrough isn't actually a property of the object, it doesn't work. How can I hide the stream information from console.log()?

(Disclaimer: I do realize it's by design and that it's probably a bad idea to hide it ;)

brandonscript
  • 68,675
  • 32
  • 163
  • 220

1 Answers1

0

console.log falls back onto util.inspect. If you have full control over the class, all you have to do is implement inspect with your custom logic. See the documentation here: https://nodejs.org/api/util.html#util_util_inspect_object_options

Daniel Williams
  • 8,673
  • 4
  • 36
  • 47
  • Looks like "Custom `inspect()` function on Objects" is probably what I'm after, but I still can't see from the docs how I can hide the stream-specific properties. – brandonscript Feb 09 '16 at 19:06