Slack messaging #169
5 changed files with 38 additions and 3 deletions
|
@ -5,5 +5,8 @@
|
||||||
"Database": {
|
"Database": {
|
||||||
"Username": "MYSQL_USERNAME",
|
"Username": "MYSQL_USERNAME",
|
||||||
"Password": "MYSQL_PASSWORD"
|
"Password": "MYSQL_PASSWORD"
|
||||||
|
},
|
||||||
|
"Logging": {
|
||||||
|
"SlackWebHook": "SLACK_WEB_HOOK"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,6 +12,10 @@ module.exports = (winston, logLevel) => {
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// winston.on('error', (err) => {
|
||||||
|
// console.log('unhandled exception in winston >> ', err);
|
||||||
|
// });
|
||||||
|
|
||||||
winston.error('Level 0');
|
winston.error('Level 0');
|
||||||
winston.warn('Level 1');
|
winston.warn('Level 1');
|
||||||
winston.info('Level 2');
|
winston.info('Level 2');
|
26
config/slackLoggerConfig.js
Normal file
26
config/slackLoggerConfig.js
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
const config = require('config');
|
||||||
|
const SLACK_WEB_HOOK = config.get('Logging.SlackWebHook');
|
||||||
|
|
||||||
|
const winstonSlackWebHook = require('winston-slack-webhook').SlackWebHook;
|
||||||
|
|
||||||
|
module.exports = (winston) => {
|
||||||
|
// add a transport for errors
|
||||||
|
winston.add(winstonSlackWebHook, {
|
||||||
|
name : 'slack-errors-transport',
|
||||||
|
level : 'error',
|
||||||
|
webhookUrl: SLACK_WEB_HOOK,
|
||||||
|
channel : '#speech-errors',
|
||||||
|
username : 'errorBot',
|
||||||
|
iconEmoji : ':face_with_head_bandage:',
|
||||||
|
});
|
||||||
|
winston.add(winstonSlackWebHook, {
|
||||||
|
name : 'slack-info-transport',
|
||||||
|
level : 'info',
|
||||||
|
webhookUrl: SLACK_WEB_HOOK,
|
||||||
|
channel : '#speech-logs',
|
||||||
|
username : 'infoBot',
|
||||||
|
iconEmoji : ':nerd_face:',
|
||||||
|
});
|
||||||
|
// send test message
|
||||||
|
winston.error('Testing slack logging... slack logging is online.');
|
||||||
|
};
|
|
@ -39,7 +39,8 @@
|
||||||
"socket.io": "^2.0.1",
|
"socket.io": "^2.0.1",
|
||||||
"socketio-file-upload": "^0.6.0",
|
"socketio-file-upload": "^0.6.0",
|
||||||
"universal-analytics": "^0.4.13",
|
"universal-analytics": "^0.4.13",
|
||||||
"winston": "^2.3.1"
|
"winston": "^2.3.1",
|
||||||
|
"winston-slack-webhook": "^0.1.5"
|
||||||
},
|
},
|
||||||
I made my own fork to fix an issue with the package, and submitted a PR to the main package. The PR was accepted, so will update this to point to main package in next update. I made my own fork to fix an issue with the package, and submitted a PR to the main package. The PR was accepted, so will update this to point to main package in next update.
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "3.19.0",
|
"eslint": "3.19.0",
|
||||||
|
|
|
@ -14,7 +14,8 @@ const db = require('./models'); // require our models for syncing
|
||||||
|
|
||||||
// configure logging
|
// configure logging
|
||||||
const logLevel = config.get('Logging.LogLevel');
|
const logLevel = config.get('Logging.LogLevel');
|
||||||
require('./config/loggerSetup.js')(logger, logLevel);
|
require('./config/loggerConfig.js')(logger, logLevel);
|
||||||
|
require('./config/slackLoggerConfig.js')(logger);
|
||||||
|
|
||||||
// trust the proxy to get ip address for us
|
// trust the proxy to get ip address for us
|
||||||
app.enable('trust proxy');
|
app.enable('trust proxy');
|
||||||
|
@ -154,5 +155,5 @@ db.sequelize
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error('Startup Error >>', error);
|
logger.error('Startup Error', error);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue
should this be billbitt?