我希望从群集中启动一些工作程序,并让每个工作人员将其输出传输回启动群集的启动脚本。此外,引导脚本将stdout传递给writeStream,而WriteStream也是由Bunyan写的。
这种工作,但我的子进程仍然记录到stdout而不是文件。
...
var errorPipe = fs.createWriteStream(logPath, {flags: 'a'});
var log = bunyan.createLogger({
name: 'webd',
streams: [
{
level: 'info',
stream: errorPipe // log INFO and above to stdout
},
{
level: 'error',
stream: errorPipe // log ERROR and above to stdout
}
]
});
process.__defineGetter__("stdout", function(){
return errorPipe;
});
process.__defineGetter__("stderr", function(){
return errorPipe;
});
// Defines what each worker needs to run
cluster.setupMaster({ exec: './index.js'}); //process.env.NODE_DIR + index
// Forks off the workers unless the server is stopping
function forkNewWorkers(callback) {
if (!stopping) {
for (var i = numWorkers(); i < workerCount; i++) {
cluster.fork('prg', [], {silent: true, stdio: [null, process.stdout, process.stderr]});
}
}
return callback;
}
...
知道为什么上面的东西不适合我的新标准输出? 谢谢!