rvagg / through2

Tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
MIT License
1.9k stars 106 forks source link

debug logging #33

Closed max-mapper closed 6 years ago

max-mapper commented 10 years ago

I've had this in the back of my mind forever and finally decided to give it a go today. I often want to do e.g. DEBUG=through2 to see the start, transform and end state of through2 streams when debugging. This is a first pass at doing so. It's just a proposal right now -- I'm open to feedback.

Example output:

screen shot 2014-11-18 at 4 07 20 pm

I tried to do it in a way that wouldn't add a dependency and also wouldn't impact perf. I think having this logic in through2 makes sense because it is used so widely. I thought about putting the debug module in another module called e.g. through2-debug but I personally don't think that would be as widely useful for debugging.

I also am open to suggestions on how to test this.

juliangruber commented 10 years ago

i find assigning random ids to streams very helpful for debugging, so in your output you can tell which stream an event belongs to...like

function Stream(){
  this.id = rand();
  if (!debugMode) this.debug = function(){}
}
Stream.prototype.debug = function(){
  console.error([this.id].concat(arguments))
}
mafintosh commented 10 years ago

LGTM from me. @juliangruber @rvagg ? (the tests seem to fail on 0.11 for some weird unrelated reason)

juliangruber commented 10 years ago

lgtm

timoxley commented 10 years ago

I usually add something very similar to this to my streams when I'm trying to figure out what's going on, overall +1.

i find assigning random ids to streams very helpful for debugging

Agree.

max-mapper commented 10 years ago

OK with some pair programming w/ @timoxley I added ids to streams and did some refactoring. I think i've addressed all the comments so far

juliangruber commented 10 years ago

looks :egg:cellent to me!

max-mapper commented 9 years ago

@rvagg ping, any feedback?

rvagg commented 9 years ago

eeek, sorry @maxogden, I'm slowly catching up on a big backlog. I don't see any negativity about this change from contributors so far so I'm not inclined to give a -1 here even though I have some reservations.

@Delapouite & @brycebaril do either of you have thoughts to add here?

stevemao commented 9 years ago

:+1:

okdistribute commented 9 years ago

As a beginner in the node streams space, I've found myself doing this manually a lot while learning. Would be great to have!

rvagg commented 9 years ago

@brycebaril and @thlorenz would you mind giving me another opinion here? I'm not a fan of this change because it's so invasive but perhaps the argument of being able to see inside makes it warranted?

thlorenz commented 9 years ago

I'm not sure this belongs into through2, even though it's a nice feature to have. A better way may be to hook into streams creation and attach handlers then.

I haven't done this myself, but if the Stream base constructor was patched to emit an event with the stream (this) as argument when it is created then the listeners could be attached there.

It's as dirty as it gets, but would only be used in DEBUG mode. As an added benefit it'd give info about all streams, not just the ones created with through2.

max-mapper commented 9 years ago

@thlorenz ah thats not a bad idea. I'll give that a shot and see if I can get my precious DEBUG data that way :)

thlorenz commented 9 years ago

@maxogden looking forward to seeing that code as until recently I wasn't even aware that you could patch constructors. I'd like to learn how that's done :)

mafintosh commented 9 years ago

@maxogden you probably need to walk require.cache and do this for all instances of readable-stream required On Tue 12 May 2015 at 03:30 Thorsten Lorenz notifications@github.com wrote:

@maxogden https://github.com/maxogden looking forward to seeing that code as until recently I wasn't even aware that you could patch constructors. I'd like to learn how that's done :)

— Reply to this email directly or view it on GitHub https://github.com/rvagg/through2/pull/33#issuecomment-101091255.

stevemao commented 9 years ago

any news @maxogden ?

rvagg commented 6 years ago

stale, sorry