JSPM

winston-slack-hook

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 31
  • Score
    100M100P100Q65697F
  • License MIT

Slack WebHook transport for Winston logging library

Package Exports

  • winston-slack-hook

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (winston-slack-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

winston-slack-hook Travis Build Status npm

Slack WebHook transport for Winston logger library

Install

$ npm install --save winston winston-slack-hook

Requirements

Usage

Basic

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

Options

Require:

  • hookUrl: Slack URL to post to
  • username: Message will be posted as this username
  • channel: The channel to post in

Optional:

  • iconEmoji: Give the username an emoji as an avatar
  • prependLevel: set to true by default, sets [level] at the beginning of the message
  • appendMeta: set to true by default, sets stringified meta at the end of the message
  • formatter(options): function for transforming the message before posting to Slack
  • colors: 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 = 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'
      }
    })
  ]
});

License

MIT © Fahad Ibnay Heylaal