下面是错误,而且我也知道它是抛出的,因为server.log文件不存在。
但是我想知道的是如何像unCaughtException那样以编程的方式处理这个错误,例如
process.on('unCaughtException', function(err){
logger.error(err1)
})下面是错误,我得到:
events.js:141
throw er; // Unhandled 'error' event
^
Error: ENOTDIR: not a directory, stat '../logs/server.log'
at Error (native)下面是..that抛出此错误的实际代码。
module.exports = new winston.Logger({
transports: [
new winston.transports.File({
level: 'info',
filename: '../logs/server.log',
json: false,
maxsize: 5242880, //5MB
maxFiles: 2,
colorize: false
}),
new winston.transports.Console({
level: 'debug',
json: false,
colorize: true
})
],
exitOnError: false
});发布于 2016-01-09 15:34:09
从代码判断,您使用的事件发射器在发生错误时发出error事件,在这种情况下,您需要侦听这些事件:
someLibrary({ logfile : '../logs/server.log' }).on('error', function(err) {
...handle the error...
});更多信息,这里。
编辑:在温斯顿的特定情况下,应该将一个error事件处理程序附加到传输实例:
module.exports = new winston.Logger({
transports: [
new winston.transports.File({
level: 'info',
filename: '../logs/server.log',
json: false,
maxsize: 5242880, //5MB
maxFiles: 2,
colorize: false
}).on('error', function(err) {
console.error(err.stack);
}),
new winston.transports.Console({
level: 'debug',
json: false,
colorize: true
})
],
exitOnError: false
});https://stackoverflow.com/questions/34695065
复制相似问题