Package Exports
- @lhkt/slack-logger
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 (@lhkt/slack-logger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
slack-logger
A simple logger that replace console.log and send the log to Slack channel with Webhook
Usage
// Import the logger const SlackLogger = require('@lhkt/slack-logger');
// Initialise the logger with your webhook URL
SlackLogger.init("Your_Webhook_URL");
// Use as an ordinary logger
SlackLogger.logi("Info Testing Log");
SlackLogger.logd("Debug Testing Log");
SlackLogger.loge("Error Testing Log");
// Example output:
(local)[INFO]
[at \xxx\xxx\index.js:xx:xx]
2021-05-01 12:34:56.789: Info Testing LogSlackLogger.init(hookUrl, env = "default", isSendSlack = true)
| Parameter | Type | Compulsory? | Default | Description |
|---|---|---|---|---|
| hookUrl | string | Y | Slack Webhook URL | |
| env | string | N | "default" | Environment tag at the beginning of every log |
| isSendSlack | boolean | N | true | Determine if logs should send to Slack. If false, the logger will only run console.log() locally. |
Get Your Webhook URL
- Create a new Slack App on https://api.slack.com/apps/
- Go to the page of your new Slack App
- Click "Basic Information" > "Add features and functionality" > "Incoming Webhooks"
- Switch on "Activate Incoming Webhooks"
- Click the "Add New Webhook to Workspace" at the bottom
- Follow the instruction to select the channel and get your webhook URL