Javascript Node.js winston日志记录使用邮件传输仅将未捕获的异常作为电子邮件发送
使用Javascript Node.js winston日志记录使用邮件传输仅将未捕获的异常作为电子邮件发送,javascript,node.js,express,logging,winston,Javascript,Node.js,Express,Logging,Winston,使用Winston模块的Mail传输,有没有办法将uncaughtException发送到电子邮件地址?我不想使用任何其他方法发送电子邮件uncaughtExceptions。我知道有很多方法可以解决这个问题,但我更希望温斯顿的邮件运输系统能够正常工作 显然,配置不支持 handleException: true 如果可以的话,那就太酷了。我使用其他传输记录所有异常,但是,当涉及到uncaughtExceptionexception时,我不仅要记录它,而且还要在抛出异常时给自己发送电子邮件,
Winston
模块的Mail
传输,有没有办法将uncaughtException
发送到电子邮件地址?我不想使用任何其他方法发送电子邮件uncaughtExceptions
。我知道有很多方法可以解决这个问题,但我更希望温斯顿的邮件运输系统能够正常工作
显然,配置不支持
handleException: true
如果可以的话,那就太酷了。我使用其他传输记录所有异常,但是,当涉及到uncaughtException
exception时,我不仅要记录它,而且还要在抛出异常时给自己发送电子邮件,这样我就可以通过ssh将其发送到系统中并解决问题。显然,我将使用永久
或pm2
作为管理员,无论如何都会重新启动应用程序
关于只能通过电子邮件发送例外情况,似乎存在一个公开的问题,但没有人对此作出回应。我做了+1
这件事,希望能有所收获
是否有人使用Winston的邮件传输仅发送
未捕获异常
。如果是,你是如何回避这个问题的?分享将不胜感激 奇怪的是,我通过更改记录器的配置方式使其正常工作。我在exceptionHandlers
中添加了邮件传输,并省略了handleException:true
位。配置如下:
var winston = require('winston');
var Mail = require('winston-mail').Mail;
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
name: 'vehicle-log',
filename: './log/vehicle.log',
level: 'info',
timestamp: true,
colorize: true,
handleExceptions: true,
humanReadableUnhandledException: true,
prettyPrint: true,
json: true,
maxsize: 5242880
})
],
exceptionHandlers: [
new winston.transports.Mail({
to:'toAddress',
from:'fromAddress',
subject: 'uncaughtException Report',
host:'smtp.relaxitsjustanexample.com',
username:'emailadd',
password:'password',
ssl: true
})
]
});
router.get('/api/burn', function(req, res) {
logger.info('ROUTE GET /api/burn');
process.nextTick(function() {
throw new Error('Catch me if you can.');
});
});
出于测试目的,我检查了一个未捕获的异常,并确保Express不会捕获它,如下所示:
var winston = require('winston');
var Mail = require('winston-mail').Mail;
var logger = new (winston.Logger)({
transports: [
new (winston.transports.File)({
name: 'vehicle-log',
filename: './log/vehicle.log',
level: 'info',
timestamp: true,
colorize: true,
handleExceptions: true,
humanReadableUnhandledException: true,
prettyPrint: true,
json: true,
maxsize: 5242880
})
],
exceptionHandlers: [
new winston.transports.Mail({
to:'toAddress',
from:'fromAddress',
subject: 'uncaughtException Report',
host:'smtp.relaxitsjustanexample.com',
username:'emailadd',
password:'password',
ssl: true
})
]
});
router.get('/api/burn', function(req, res) {
logger.info('ROUTE GET /api/burn');
process.nextTick(function() {
throw new Error('Catch me if you can.');
});
});
uncaughtException
通过文件传输记录,以及通过邮件传输发送电子邮件
当它不工作时,我对传输进行了不同的配置,然后我发现我可以使用
exceptionHandlers
。我不知道是使用例外handles
让它工作了还是其他什么,但不管它是否工作 ffd在示例中不使用gmail,这就像送一个人去赌场谋生一样