Skip to content

Instantly share code, notes, and snippets.

@Unitecho
Created April 16, 2013 04:13
Show Gist options
  • Save Unitecho/5393289 to your computer and use it in GitHub Desktop.
Save Unitecho/5393289 to your computer and use it in GitHub Desktop.
Intercept console.log output and write to file
var util = require('util');
var fs = require('fs');
var log = fs.createWriteStream('stdout.log');
console.log = console.info = function(t) {
var out;
if (t && ~t.indexOf('%')) {
out = util.format.apply(util, arguments);
process.stdout.write(out + '\n');
return;
} else {
out = Array.prototype.join.call(arguments, ' ');
}
out && log.write(out + '\n');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment