spee.ch/helpers/configureSlack.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
const slackConfig = require('../config/slackConfig.js');
module.exports = (winston) => {
2018-03-09 11:20:13 -08:00
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
if (slackWebHook) {
2017-11-06 15:18:45 -08:00
// add a transport for errors to slack
if (slackErrorChannel) {
2017-12-08 10:25:05 -08:00
winston.add(winstonSlackWebHook, {
name : 'slack-errors-transport',
level : 'warn',
webhookUrl: slackWebHook,
channel : slackErrorChannel,
2017-12-08 10:25:05 -08:00
username : 'spee.ch',
iconEmoji : ':face_with_head_bandage:',
});
};
if (slackInfoChannel) {
2017-12-08 10:25:05 -08:00
winston.add(winstonSlackWebHook, {
name : 'slack-info-transport',
level : 'info',
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
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
}
};