2018-06-06 03:55:44 +02:00
|
|
|
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
|
|
|
const logger = require('winston');
|
|
|
|
|
2018-06-06 21:01:11 +02:00
|
|
|
const config = require('@config/slackConfig');
|
|
|
|
const {slackWebHook, slackErrorChannel, slackInfoChannel} = config;
|
2018-06-06 03:55:44 +02:00
|
|
|
|
|
|
|
function configureSlack () {
|
2018-06-06 21:01:11 +02:00
|
|
|
logger.info('configuring slack logger...');
|
2018-06-06 03:55:44 +02:00
|
|
|
if (!config) {
|
|
|
|
return logger.warn('No slack config found');
|
|
|
|
}
|
|
|
|
// update slack webhook settings
|
|
|
|
if (!slackWebHook) {
|
2018-06-06 21:01:11 +02:00
|
|
|
return logger.info('Slack logging is not enabled because no slackWebHook config var provided.');
|
2018-06-06 03:55:44 +02:00
|
|
|
}
|
|
|
|
// add a transport for errors to slack
|
|
|
|
if (slackErrorChannel) {
|
|
|
|
logger.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-errors-transport',
|
|
|
|
level : 'warn',
|
|
|
|
webhookUrl: slackWebHook,
|
|
|
|
channel : slackErrorChannel,
|
|
|
|
username : 'spee.ch',
|
|
|
|
iconEmoji : ':face_with_head_bandage:',
|
|
|
|
});
|
2018-06-06 21:01:11 +02:00
|
|
|
} else {
|
|
|
|
logger.warn('No slack error channel logging set up');
|
2018-06-06 03:55:44 +02:00
|
|
|
}
|
|
|
|
// add a transport for info in slack
|
|
|
|
if (slackInfoChannel) {
|
|
|
|
logger.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-info-transport',
|
|
|
|
level : 'info',
|
|
|
|
webhookUrl: slackWebHook,
|
|
|
|
channel : slackInfoChannel,
|
|
|
|
username : 'spee.ch',
|
|
|
|
iconEmoji : ':nerd_face:',
|
|
|
|
});
|
2018-06-06 21:01:11 +02:00
|
|
|
} else {
|
|
|
|
logger.warn('No slack info channel logging set up');
|
2018-06-06 03:55:44 +02:00
|
|
|
}
|
|
|
|
// send test messages
|
|
|
|
logger.info('Slack logging is online.');
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = configureSlack;
|