2017-09-13 15:41:52 -07:00
|
|
|
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
2018-03-09 16:45:24 -08:00
|
|
|
const slackConfig = require('../config/slackConfig.js');
|
2017-09-13 15:41:52 -07:00
|
|
|
|
2018-03-09 16:45:24 -08:00
|
|
|
module.exports = (winston) => {
|
2018-03-09 11:20:13 -08:00
|
|
|
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
|
2017-12-16 09:55:29 -08:00
|
|
|
if (slackWebHook) {
|
2017-11-06 15:18:45 -08:00
|
|
|
// add a transport for errors to slack
|
2017-12-16 09:55:29 -08:00
|
|
|
if (slackErrorChannel) {
|
2017-12-08 10:25:05 -08:00
|
|
|
winston.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-errors-transport',
|
|
|
|
level : 'warn',
|
2017-12-16 09:55:29 -08:00
|
|
|
webhookUrl: slackWebHook,
|
|
|
|
channel : slackErrorChannel,
|
2017-12-08 10:25:05 -08:00
|
|
|
username : 'spee.ch',
|
|
|
|
iconEmoji : ':face_with_head_bandage:',
|
|
|
|
});
|
|
|
|
};
|
2017-12-16 09:55:29 -08:00
|
|
|
if (slackInfoChannel) {
|
2017-12-08 10:25:05 -08:00
|
|
|
winston.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-info-transport',
|
|
|
|
level : 'info',
|
2017-12-16 09:55:29 -08:00
|
|
|
webhookUrl: slackWebHook,
|
|
|
|
channel : slackInfoChannel,
|
2017-12-08 10:25:05 -08:00
|
|
|
username : 'spee.ch',
|
|
|
|
iconEmoji : ':nerd_face:',
|
|
|
|
});
|
|
|
|
};
|
2017-11-06 15:18:45 -08:00
|
|
|
// send test message
|
2017-11-07 07:14:38 -08:00
|
|
|
winston.error('Slack "error" logging is online.');
|
|
|
|
winston.info('Slack "info" logging is online.');
|
2017-09-25 08:49:28 -07:00
|
|
|
} else {
|
2017-12-08 10:25:05 -08:00
|
|
|
winston.warn('Slack logging is not enabled because no slackWebHook config var provided.');
|
2017-09-25 08:49:28 -07:00
|
|
|
}
|
2017-09-13 15:41:52 -07:00
|
|
|
};
|