admin管理员组文章数量:1415069
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.
本文标签:
版权声明:本文标题:javascript - Node.js winston logging using mail transport to send only uncaughtException as an email - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745231171a2648830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论