![](/img/trans.png)
[英]How to solve nodejs uncaughtException: Connection already released error and MaxListenersExceededWarning?
[英]uncaughtException then appendFile on error will this cause problems? NodeJs
我很好奇因為 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)
});
})
fs.appendFile
,看起來您的程序每次以fs.appendFile
結束時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
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.