spee.ch/server/helpers/configureSlack.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
2018-03-19 23:34:32 +01:00
const slackConfig = require('../../devConfig/slackConfig.js');
module.exports = (winston) => {
2018-03-09 20:20:13 +01:00
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
if (slackWebHook) {
2017-11-07 00:18:45 +01:00
// add a transport for errors to slack
if (slackErrorChannel) {
2017-12-08 19:25:05 +01:00
winston.add(winstonSlackWebHook, {
name : 'slack-errors-transport',
level : 'warn',
webhookUrl: slackWebHook,
channel : slackErrorChannel,
2017-12-08 19:25:05 +01:00
username : 'spee.ch',
iconEmoji : ':face_with_head_bandage:',
});
};
if (slackInfoChannel) {
2017-12-08 19:25:05 +01:00
winston.add(winstonSlackWebHook, {
name : 'slack-info-transport',
level : 'info',
webhookUrl: slackWebHook,
channel : slackInfoChannel,
2017-12-08 19:25:05 +01:00
username : 'spee.ch',
iconEmoji : ':nerd_face:',
});
};
2017-11-07 00:18:45 +01:00
// send test message
winston.error('Slack "error" logging is online.');
winston.info('Slack "info" logging is online.');
2017-09-25 17:49:28 +02:00
} else {
2017-12-08 19:25:05 +01:00
winston.warn('Slack logging is not enabled because no slackWebHook config var provided.');
2017-09-25 17:49:28 +02:00
}
};