I want to log only errors that would crash the system to a error.log separate file.
I'm already logging http requests with Morgan to a file using this code:
// create a write stream (in append mode)
var accessLogStream = fs.createWriteStream(__dirname + '/logs/access.log', {flags: 'a'})
// setup the logger
app.use(logger('short', {stream: accessLogStream}));
But I want to log to a separate file (error.log) this kind of app errors:
//Error handling, avoiding crash
process.on('uncaughtException', function (err) {
console.error(err);
console.log("Node NOT Exiting...");
});
How can I log error.stack to that file?