logger-nodejs-slack-plugin
v1.1.0
Published
A plugin for logger-nodejs that allows you to send messages of your choice to slack
Downloads
204
Maintainers
Readme
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 slackchannel
(required): The channel you want messages sent tousername
(required): The username you want to use for these slack messageslogLevel
: The minimum log level. See here for all available log levelslevelChannels
: 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
tofalse