Node.js winston 日志记录使用邮件传输仅将 uncaughtException 作为电子邮件发送
Node.js winston logging using mail transport to send only uncaughtException as an email
有没有什么方法可以使用 Winston
模块的 Mail
传输将 uncaughtException
发送到电子邮件地址?我不想使用任何其他方法来发送电子邮件 uncaughtExceptions
。我知道有办法解决这个问题,但我更希望让 Winston 的邮件传输正常工作。
显然配置不支持
handleException: true
如果可以的话会很酷。我使用其他传输来记录所有异常,但是,当涉及到 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
})
]
});
出于测试目的,我通过一个 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
由文件传输记录并通过邮件传输通过电子邮件发送。
当它不工作时,我对传输进行了不同的配置,然后我发现我可以使用 exceptionHandlers
。我不知道使用 exceptionHanlders
是否使它工作或其他什么,但不管它是否工作。
有没有什么方法可以使用 Winston
模块的 Mail
传输将 uncaughtException
发送到电子邮件地址?我不想使用任何其他方法来发送电子邮件 uncaughtExceptions
。我知道有办法解决这个问题,但我更希望让 Winston 的邮件传输正常工作。
显然配置不支持
handleException: true
如果可以的话会很酷。我使用其他传输来记录所有异常,但是,当涉及到 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
})
]
});
出于测试目的,我通过一个 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
由文件传输记录并通过邮件传输通过电子邮件发送。
当它不工作时,我对传输进行了不同的配置,然后我发现我可以使用 exceptionHandlers
。我不知道使用 exceptionHanlders
是否使它工作或其他什么,但不管它是否工作。