-
Notifications
You must be signed in to change notification settings - Fork 106
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
debug logging #33
Conversation
@@ -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') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true, probably not
LGTM from me. @juliangruber @rvagg ? (the tests seem to fail on 0.11 for some weird unrelated reason) |
lgtm |
I usually add something very similar to this to my streams when I'm trying to figure out what's going on, overall +1.
Agree. |
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 |
looks 🥚cellent to me! |
@rvagg ping, any feedback? |
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? |
👍 |
As a beginner in the node streams space, I've found myself doing this manually a lot while learning. Would be great to have! |
@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? |
I'm not sure this belongs into through2, even though it's a nice feature to have. I haven't done this myself, but if the It's as dirty as it gets, but would only be used in |
@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 :) |
@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 :) |
@maxogden you probably need to walk require.cache and do this for all
|
any news @maxogden ? |
stale, sorry |
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:
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.