Is there any way to send uncaughtException
to an email address using Winston
module's Mail
transport? I don't want to use any other approach to email uncaughtExceptions
. I kow that there are ways round this but, I am more keen to getting Winston's Mail transport working.
Apparently the configuration does not support
handleException: true
Would be cool though if it could. I use other transports to log all exceptions but, when it es to uncaughtException
exception I not only want to log it but also email myself when they are thrown so I can ssh into the system and resolve the issue. Obviously I will be using either forever
or pm2
as supervisor which would restart the app anyway.
There seem to be an open issue about being able to email only exceptions but, nobody has responded to that. I did +1
the issue in the hope of getting something.
Has anyone used Winston's Mail transport to send uncaughtException
only. If yes, how did you get around this issue? Sharing would be appreciated.
Is there any way to send uncaughtException
to an email address using Winston
module's Mail
transport? I don't want to use any other approach to email uncaughtExceptions
. I kow that there are ways round this but, I am more keen to getting Winston's Mail transport working.
Apparently the configuration does not support
handleException: true
Would be cool though if it could. I use other transports to log all exceptions but, when it es to uncaughtException
exception I not only want to log it but also email myself when they are thrown so I can ssh into the system and resolve the issue. Obviously I will be using either forever
or pm2
as supervisor which would restart the app anyway.
There seem to be an open issue about being able to email only exceptions but, nobody has responded to that. I did +1
the issue in the hope of getting something.
Has anyone used Winston's Mail transport to send uncaughtException
only. If yes, how did you get around this issue? Sharing would be appreciated.
1 Answer
Reset to default 6Strangely enough, I got it to work by changing how I configured the logger. I added the Mail transport inside the exceptionHandlers
and omitted the handleException: true
bit. The configuration is as follow:
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.',
username:'emailadd',
password:'password',
ssl: true
})
]
});
For testing purpose, I through an uncaughtException and made sure that Express don't catch it as follow:
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
gets logged by File transport as well as emailed by Mail transport.
When it was not working, I had configured the transport differently then I found out that I can use exceptionHandlers
. I don't know if using exceptionHanlders
made it work or something else but, regardless it is working.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745231171a4617684.html
评论列表(0条)