Node: A new event to the process. The log event

Created on 6 Aug 2020  路  5Comments  路  Source: nodejs/node

Is your feature request related to a problem? Please describe.

A way to check when something is logged to stdout

Describe the solution you'd like

Whenever something is written to process.stdout, the log event is emitted with whatever is written into stdout.

Describe alternatives you've considered

N/A

feature request stdio

Most helpful comment

I think you'll be disappointed vis-a-vis compactness because you'll have to deal with ANSI control codes in the data. You're not getting a plain string.

I'll leave this open for a few more days but if no one else chimes in with strong support, I'm going to close this.

One reason for not implementing this is that emitting events is not zero cost. It's not a huge cost but little bits add up.

All 5 comments

I guess my question is: what do you need that for? What's the use case?

process.stdout at its core is a stream.Writable. Other stream.Writable instances don't emit such events either.

You can monkey-patch process.stdout to intercept writes:

process.stdout.write = (function(write) {
  return function(...args) {
    console.error(args)
    return write.apply(this, args)
  }
})(process.stdout.write)

I was trying to make a logger which would log everything via this event, it would just allow me to make everything more compact. Still think it'd be cool.

I think you'll be disappointed vis-a-vis compactness because you'll have to deal with ANSI control codes in the data. You're not getting a plain string.

I'll leave this open for a few more days but if no one else chimes in with strong support, I'm going to close this.

One reason for not implementing this is that emitting events is not zero cost. It's not a huge cost but little bits add up.

Ah I get it

I believe the consensus here is that we're not going to make this change. I'll go ahead and close this.

Was this page helpful?
0 / 5 - 0 ratings