Raf*_*Raf 2 javascript logging node.js express winston
有没有办法uncaughtException使用Winston模块的Mail传输发送到电子邮件地址?我不想使用任何其他方法来发送电子邮件uncaughtExceptions。我知道有办法解决这个问题,但我更希望让 Winston 的邮件传输工作。
显然配置不支持
handleException: true
Run Code Online (Sandbox Code Playgroud)
如果可以的话会很酷。我使用其他传输来记录所有异常,但是,当涉及到uncaughtException异常时,我不仅要记录它,还要在抛出异常时给自己发送电子邮件,以便我可以通过 ssh 进入系统并解决问题。显然,我将使用任一个forever或pm2作为主管,无论如何都会重新启动应用程序。
关于只能通过电子邮件发送例外情况似乎存在一个悬而未决的问题,但是没有人对此做出回应。我做+1了这个问题,希望得到一些东西。
有没有人使用温斯顿的邮件传输uncaughtException只发送。如果是,你是如何解决这个问题的?分享将不胜感激。
奇怪的是,我通过改变我配置记录器的方式让它工作。我在里面添加了邮件传输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
})
]
});
Run Code Online (Sandbox Code Playgroud)
出于测试目的,我通过了一个 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.');
});
});
Run Code Online (Sandbox Code Playgroud)
uncaughtException 通过文件传输记录以及通过邮件传输通过电子邮件发送。
当它不工作时,我以不同的方式配置了传输然后我发现我可以使用exceptionHandlers. 我不知道使用exceptionHanlders它是否有效或其他什么,但是,不管它是否有效。
| 归档时间: |
|
| 查看次数: |
2777 次 |
| 最近记录: |