Created
June 15, 2017 09:10
-
-
Save royalgarter/dfe30300984522d4f1bf1b06f1018dfd to your computer and use it in GitHub Desktop.
NodeJS console hook to stdout, stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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