-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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') | ||
|
||
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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. true, probably not |
||
this.on('finish', function() { | ||
console.error(' through2 finish') | ||
}) | ||
this.on('end', function() { | ||
console.error(' through2 end') | ||
}) | ||
} | ||
} | ||
|
||
inherits(DestroyableTransform, Transform) | ||
|
@@ -50,8 +61,11 @@ function through2 (construct) { | |
|
||
// main export, just make me a transform stream! | ||
module.exports = through2(function (options, transform, flush) { | ||
if (DEBUG) console.error(' through2 initialize') | ||
|
||
var t2 = new DestroyableTransform(options) | ||
|
||
if (DEBUG) transform = debugTransform(transform, t2) | ||
t2._transform = transform | ||
|
||
if (flush) | ||
|
@@ -64,6 +78,8 @@ module.exports = through2(function (options, transform, flush) { | |
// make me a reusable prototype that I can `new`, or implicitly `new` | ||
// with a constructor call | ||
module.exports.ctor = through2(function (options, transform, flush) { | ||
if (DEBUG) console.error(' through2.ctor initialize') | ||
|
||
function Through2 (override) { | ||
if (!(this instanceof Through2)) | ||
return new Through2(override) | ||
|
@@ -75,6 +91,7 @@ module.exports.ctor = through2(function (options, transform, flush) { | |
|
||
inherits(Through2, DestroyableTransform) | ||
|
||
if (DEBUG) transform = debugTransform(transform) | ||
Through2.prototype._transform = transform | ||
|
||
if (flush) | ||
|
@@ -85,12 +102,22 @@ module.exports.ctor = through2(function (options, transform, flush) { | |
|
||
|
||
module.exports.obj = through2(function (options, transform, flush) { | ||
if (DEBUG) console.error(' through2.obj initialize') | ||
|
||
var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options)) | ||
|
||
if (DEBUG) transform = debugTransform(transform, t2) | ||
t2._transform = transform | ||
|
||
if (flush) | ||
t2._flush = flush | ||
|
||
return t2 | ||
}) | ||
|
||
function debugTransform(transform, ctx) { | ||
return function debugTransform(chunk, enc, callback) { | ||
console.error(' through2 transform', typeof chunk, {length: chunk.length, encoding: enc}) | ||
transform.apply(ctx || this, arguments) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should always be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call, I dont know what I was thinking |
||
} | ||
} |
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 doDEBUG=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