Created
April 16, 2013 04:13
-
-
Save Unitecho/5393289 to your computer and use it in GitHub Desktop.
Intercept console.log output and write to file
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 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