Slack WebHook transport for Winston logging library
npm install winston-slack-hook> Slack WebHook transport for Winston logger library
```
$ npm install --save winston winston-slack-hook
* Use winston
* Set up Slack incoming webhook
`js
var winston = require('winston');
var SlackHook = require('winston-slack-hook');
var Logger = winston.Logger;
var Console = winston.transports.Console;
var logger = new Logger({
transports: [
new Console({}),
new SlackHook({
hookUrl: 'https://hooks.slack.com/services/XXX/YYY/ZZZ',
username: 'bot',
channel: '#logs'
})
]
});
logger.info('I am being logged here'); // will be sent to both console and Slack
`
Require:
* hookUrl: Slack URL to post tousername
* : Message will be posted as this usernamechannel
* : The channel to post in
Optional:
* iconEmoji: Give the username an emoji as an avatarprependLevel
* : set to true by default, sets [level] at the beginning of the messageappendMeta
* : set to true by default, sets stringified meta at the end of the messageformatter(options)
* : function for transforming the message before posting to Slackcolors
* : set to {} by default (no colors), set the color of the message given a level.
Messages can be formatted further before posting to Slack:
`js
var logger = new Logger({
transports: [
new SlackHook({
hookUrl: 'https://hooks.slack.com/services/XXX/YYY/ZZZ',
username: 'bot',
channel: '#logs',
formatter: function (options) {
var message = options.message; // original message
// var level = options.level;
// var meta = options.meta;
// do something with the message
return message;
},
colors: {
warn: 'warning',
error: 'danger',
info: 'good',
debug: '#bbddff'
}
})
]
});
``
MIT © Fahad Ibnay Heylaal