Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug logging #33

Closed
wants to merge 3 commits into from
Closed

debug logging #33

wants to merge 3 commits into from

Conversation

max-mapper
Copy link
Contributor

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.

@@ -2,9 +2,20 @@ var Transform = require('readable-stream/transform')
, inherits = require('util').inherits
, xtend = require('xtend')

var debug = process.env['DEBUG'] || ''
var DEBUG = (debug === '*') || (debug === 'through2')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe (debug === '*') || (/through2/.test(debug)) so you can do DEBUG=through2,another-module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, updated in max-mapper@7445786

@juliangruber
Copy link

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

function DestroyableTransform(opts) {
Transform.call(this, opts)
this._destroyed = false
if (DEBUG) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for perf reasons you probably want to put the content of this if inside a function to avoid these functions being hoisted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would only happen once though at the time of stream construction, do you think that would make a noticeable perf impact?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, probably not

@mafintosh
Copy link
Collaborator

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

@juliangruber
Copy link

lgtm

@timoxley
Copy link

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
Copy link
Contributor Author

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
Copy link

looks 🥚cellent to me!

@max-mapper
Copy link
Contributor Author

@rvagg ping, any feedback?

@rvagg
Copy link
Owner

rvagg commented Dec 23, 2014

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
Copy link
Contributor

stevemao commented Mar 4, 2015

👍

@okdistribute
Copy link

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
Copy link
Owner

rvagg commented May 11, 2015

@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
Copy link

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
Copy link
Contributor Author

@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
Copy link

@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
Copy link
Collaborator

@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
#33 (comment).

@stevemao
Copy link
Contributor

any news @maxogden ?

@rvagg
Copy link
Owner

rvagg commented Nov 6, 2018

stale, sorry

@rvagg rvagg closed this Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants