Feature request: mute
Thanks for sharing your module! I'm looking for a way to both intercept and mute the log. By commenting out this line I think it would work.
Would you be interested in a PR or should I fork?
Not returning in the interceptor should work, shouldn't it?
I think SimenB is basically right, you can see the first example (output is muted) in the README compared to the 2nd one under the modification section (the 'intercepter' returns a manipulated string). Although, I think process.stdout.write is still being called regardless, but I am not sure this has an effect.
@SimenB Nor sure what you mean by Not returning in the interceptor. Commenting out captured_text += txt or removing the callback altogether does not work.
@sfarthin But the log is not muted in the first example. The part below logs a and b.
var intercept = require("intercept-stdout"),
captured_text = "";
var unhook_intercept = intercept(function(txt) {
captured_text += txt;
});
console.log("a");
unhook_intercept(); // Let's stop capturing stdout.
console.log("b");
Nevermind. I made something that mutes the log (although I think I lost the streaming aspect but that's fine by me).
@karlpokus correct. @sfarthin was talking about 2nd example in the readme.
It's not obvious from the readme, but after studying tests I realised that to suppress output empty string should be returned (not undefined).
let unhook_intercept = intercept(function (line) {
// ...
return ''
})
@sfarthin could be useful to mention that not returning a string will result in print of the original string.
Sounds good, would you mind doing a PR?
This sort of can be closed. The readme has the info but on the npm site, the changes to the readme are not there.