3.0.0-rc.4 • Published 2 years ago
@debugr/slack-handler v3.0.0-rc.4
Slack Log Handler for Debugr
This log handler will send each entry with a log level at or above a configured threshold as a message to a configured Slack channel.
Installation
npm install --save @debugr/slack-handler
Usage
import { Logger, LogLevel } from '@debugr/core';
import { SlackLogHandler } from '@debugr/slack-handler';
const globalContext = {
applicationName: 'example',
};
const logger = new Logger(globalContext, [
new SlackLogHandler({
threshold: LogLevel.FATAL,
webhookUrl: 'your slack webhook url',
}),
]);
logger.fatal('Something failed miserably!');
The SlackLogHandler
constructor accepts a required options
object
with the following keys as the first argument:
Option | Type | Default | Description |
---|---|---|---|
webhookUrl | string | (required) | A Slack webhook URL; see the Slack API docs on how to obtain one. |
threshold | LogLevel , number | LogLevel.ERROR | The lowest level of entries which will be posted to the configured channel. Any entries below this level will be ignored. |
channel | string | The Slack channel ID the message should be posted to. This only works with legacy Slack webhooks. | |
username | string | The slack username the message should be posted under. This only works with legacy Slack webhooks. | |
iconUrl | string | The URL of an icon to be used in place of the default icon. This only works with legacy Slack webhooks. | |
iconEmoji | string | An emoji code string to use in place of the default icon. This only works with legacy Slack webhooks. | |
errorCallback | (err: Error) => void | (see description) | A callback which will be called when sending a message to Slack fails. The default callback will simply log the error into the console. |
bodyMapper | (entry: LogEntry) => Record<string, any> | (see description) | A callback mapping the log entry to payload to be sent to the configured webhook URL. At a minimum the payload must include a text key with a string content. |