uncaughtException然后appendFile on error这会导致问题吗?NodeJs
uncaughtException then appendFile on error will this cause problems? NodeJs
我很好奇,如果因为process.exit(1)是在一个异步的回调操作时,如果发生原始错误的地方将继续运行并处于不稳定状态。我试图将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)
});
})
实际上,看起来您的程序每次完成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
});
});
相关文章:
- 为变量分配多个nodejs导出返回值时出现问题
- 导出模块 NodeJS 时出现问题
- 使用nodejs和id3打开文件时出现问题
- Nodejs请求之后是请求同步问题
- NodeJS回调范围问题
- NodeJs 套接字连接问题
- OpenShift NodeJS 应用程序 503 错误(端口问题?
- AngularJS:http 链调用问题和 NodeJS:在多个 http 调用中使用变量的问题
- 来自 NodeJS 脚本的注释是否有可能产生内存问题
- 在 NodeJS 中复制缓冲区时出现问题
- NodeJs ExpressJS 错误处理问题
- nodejs 请求 - toString 失败 - 大文件的缓冲区大小问题 (maxBufferSize)
- 开始使用 NodeJS 和 SocketIO 时遇到问题
- NodeJS (Express 4) + i18n + 下划线:模板中的翻译问题
- 简单的 NodeJS 路由器问题 -- 行为异常的案例语句
- Soundcloud 使用 NodeJS 登录和喜欢声音问题 - 401 未经授权
- NodeJS MongoDB 连接字符串问题
- 角度教程:Nodejs 和证书问题
- Nodejs和一些更基本的问题
- nodejs中的变量范围问题