winston-slack-hook
Slack WebHook transport for Winston logger library
Install
$ npm install --save winston winston-slack-hook
Requirements
- Use winston
- Set up Slack incoming webhook
Usage
Basic
var winston = ;var SlackHook = ; var Logger = winstonLogger;var Console = winstontransportsConsole; var logger = transports: {} hookUrl: 'https://hooks.slack.com/services/XXX/YYY/ZZZ' username: 'bot' channel: '#logs' ; logger; // will be sent to both console and Slack
Options
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 totrue
by default, sets[level]
at the beginning of the messageappendMeta
: set totrue
by default, sets stringifiedmeta
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.
Formatter and colors
Messages can be formatted further before posting to Slack:
var logger = transports: hookUrl: 'https://hooks.slack.com/services/XXX/YYY/ZZZ' username: 'bot' channel: '#logs' { var message = optionsmessage; // 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' ;
License
MIT © Fahad Ibnay Heylaal