node console.log输出到文件

var fs      = require('fs')
var util    = require('util')

var logPath = 'upgrade.log'
var logFile = fs.createWriteStream(logPath, { flags: 'a' })

console.log = function() {
    logFile.write(util.format.apply(null, arguments) + '\n')
    process.stdout.write(util.format.apply(null, arguments) + '\n')
}

你可能感兴趣的:(node console.log输出到文件)