我很好奇,因为process.exit(1)处于异步操作的回调中,如果原始错误发生的地方会继续运行并处于不稳定状态,那么appendFile。我试图将process.exit(1)与fs放在一起,但它不会写。
更好的方法,以创建一个记录错误,将登录的任何错误,将不胜感激。。
const fs = require('fs');
process.on('uncaughtException', e1 => {
fs.appendFile('./logs/error.log', e1.stack, e2 => {
//if (e1 || e2) console.log(e1,e2);
process.exit(1)
});
})发布于 2016-09-22 00:22:23
实际上,当您的程序每次使用fs.appendFile完成时,它都会以错误代码退出控制台。一旦碰到这个问题,process.exit就应该杀死运行中的其他任何东西。
我可能会这样做:
const fs = require('fs');
process.on('uncaughtException', function (err) {
fs.appendFile('./logs/error.log', err.stack, (fserr) => {
if (err) console.log('FS ERROR', fserr); //now includes the fs error in log
console.log(err); //maybe include error from uncaughtException?
process.exit(1); //exit with error code
});
});https://stackoverflow.com/questions/39628354
复制相似问题