Skip to content

Instantly share code, notes, and snippets.

@royalgarter
Created June 15, 2017 09:10
Show Gist options
  • Save royalgarter/dfe30300984522d4f1bf1b06f1018dfd to your computer and use it in GitHub Desktop.
Save royalgarter/dfe30300984522d4f1bf1b06f1018dfd to your computer and use it in GitHub Desktop.
NodeJS console hook to stdout, stderr
var exports = module.exports;
exports.setup = function(callback) {
var write = process.stdout.write;
process.stdout.write = (function (stub) {
return function (string, encoding, fd) {
stub.apply(process.stdout, arguments);
callback(string, encoding, fd);
};
})(process.stdout.write);
var write2 = process.stderr.write;
process.stderr.write = (function (stub) {
return function (string, encoding, fd) {
stub.apply(process.stderr, arguments);
callback(string, encoding, fd);
};
})(process.stderr.write);
return function() {
process.stdout.write = write;
process.stderr.write = write2;
};
};
/* HOW TO USE
require('hook_stdout.js').setup(function(string, encoding, fd) {
return logentries.info(string);
});
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment