2017-09-14 00:41:52 +02:00
|
|
|
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
2018-03-19 23:34:32 +01:00
|
|
|
const slackConfig = require('../../devConfig/slackConfig.js');
|
2017-09-14 00:41:52 +02:00
|
|
|
|
2018-03-10 01:45:24 +01:00
|
|
|
module.exports = (winston) => {
|
2018-03-09 20:20:13 +01:00
|
|
|
const {slackWebHook, slackErrorChannel, slackInfoChannel} = slackConfig;
|
2017-12-16 18:55:29 +01:00
|
|
|
if (slackWebHook) {
|
2017-11-07 00:18:45 +01:00
|
|
|
// add a transport for errors to slack
|
2017-12-16 18:55:29 +01:00
|
|
|
if (slackErrorChannel) {
|
2017-12-08 19:25:05 +01:00
|
|
|
winston.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-errors-transport',
|
|
|
|
level : 'warn',
|
2017-12-16 18:55:29 +01:00
|
|
|
webhookUrl: slackWebHook,
|
|
|
|
channel : slackErrorChannel,
|
2017-12-08 19:25:05 +01:00
|
|
|
username : 'spee.ch',
|
|
|
|
iconEmoji : ':face_with_head_bandage:',
|
|
|
|
});
|
|
|
|
};
|
2017-12-16 18:55:29 +01:00
|
|
|
if (slackInfoChannel) {
|
2017-12-08 19:25:05 +01:00
|
|
|
winston.add(winstonSlackWebHook, {
|
|
|
|
name : 'slack-info-transport',
|
|
|
|
level : 'info',
|
2017-12-16 18:55:29 +01:00
|
|
|
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
|
2017-11-07 16:14:38 +01:00
|
|
|
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
|
|
|
}
|
2017-09-14 00:41:52 +02:00
|
|
|
};
|