Skip to content

mistermoe/logger-nodejs-slack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slack Logging Plugin

A plugin for logger-nodejs that allows you to send logs to slack

Usage:

const Logger = require('logger-nodejs');
const SlackPlugin = require('logger-nodejs-slack-plugin');

const slackPlugin = new SlackPlugin({
    webhook: 'https://hooks.slack.com/services/your/webhook',
    channel: '#api-errors',
    username: 'API',
    logLevel: 'error'
});

const log = new Logger({ plugins: [slackPlugin] });
  • Now, every message of at least level error will be sent to the configured slack channel.

Configuration Options:

  • The following properties can be provided during instantiation:
    • webhook (required): The url provided by slack
    • channel (required): The channel you want messages sent to
    • username (required): The username you want to use for these slack messages
    • logLevel: The minimum log level. See here for all available log levels
    • levelChannels: An object containing keys as log levels and channel names for those log levels. This allows you to send logs of different levels to different channels.
    {
        "fatal": "#general",
        "error": "#errors"
    }
    

Alternative Usage:

  • You can also choose what messages to send to slack on a per-message basis like so:
const Logger = require('logger-nodejs');
const SlackPlugin = require('logger-nodejs-slack-plugin');

const slackPlugin = new SlackPlugin({
    webhook: 'https://hooks.slack.com/services/your/webhook',
    channel: '#api-errors',
    username: 'API',
});

const log = new Logger({ plugins: [slackPlugin] });

log.info('Application Started!', { notifySlack: true });
  • You can prevent certain messages from getting sent to slack by setting notifySlack to false

About

A plugin for logger-nodejs that allows you to send messages of your choice to slack

Resources

Stars

Watchers

Forks

Packages

No packages published