使用邮件传输的Node.js winston日志logging只发送uncaughtException作为电子邮件
有没有办法将uncaughtException
发送到使用Winston
模块的Mail
传输的电子邮件地址? 我不想使用任何其他方法来发送电子邮件uncaughtExceptions
。 我发誓,有这样的方式,但我更热衷Winston的邮件传输工作。
显然这个configuration不支持
handleException: true
如果可以的话,会很酷。 我使用其他传输来logging所有的exception,但是,当涉及到uncaughtException
exception我不仅要logging它,而且还会发送电子邮件,当我们可以ssh进入系统并解决问题。 显然我会forever
或使用pm2
作为主pipe,无论如何将重新启动应用程序。
似乎只能通过电子邮件发送例外,但没有人回应这个问题。 我做了+1
这个问题,希望得到的东西。
有没有人使用Winston的邮件传输发送uncaughtException
只。 如果是的话,你是如何解决这个问题的? 分享将不胜感激。
奇怪的是,我通过改变我如何configurationlogging器来实现它。 我在exceptionHandlers
里面添加了Mail传输,并省略了handleException: true
位。 configuration如下:
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 }) ] });
出于testing目的,我通过一个uncaughtException,并确保Express不赶上它如下:
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
通过文件传输logging并通过邮件传输发送。
当它不工作,我已经configuration了不同的运输,然后我发现我可以使用exceptionHandlers
。 我不知道如果使用exceptionHanlders
使它工作或其他东西,但无论它是否工作。