@kevit/winston-channel-logger
v1.0.4
Published
Library to dump winston logs to Business Communication Platforms such as MS Teams, Slack, etc.
Downloads
6
Readme
README
This repository contains a Winston Channel Logger for logging messages to various platforms such as Microsoft Teams, Slack, and Discord. The module utilizes incoming Webhooks and Platform APIs to send messages.
Installation
To install the module into your project, you can use npm or yarn:
npm install @kevit/winston-channel-logger
or
yarn add @kevit/winston-channel-logger
Usage
To use the custom transport module, follow these steps:
- Import it into your code as:
import { WinstonChannelLogger } from '@kevit/winston-channel-logger';
- Initialize the object of
WinstonChannelLogger
as:
const winstonChannelLogger = new WinstonChannelLogger({
format: format.uncolorize(),
level:'log_level',
platforms: [{
platformName: 'ms-teams',
webhookUrl: '<teams-webhook-url>',
},
{
platformName: 'slack',
token: '<slack-token>',
channelId: '<slack-channel-id>',
},
{
platformName: 'discord',
webhookUrl: '<discord-webhook-url>',
}],
});
- Finally, attach this custom logger in
transports
array ofcreateLogger
For ex:
const logger = createLogger({
transports: [new transports.Console({ level:'silly'}), winstonChannelLogger],
});
In the above configuration one or more channels can be configured by passing channel specific argument Channel specific configuration. Configurations can be made as follows:
Microsoft Teams
- Value for
platformName
will bems-teams
. - For getting
teams-webhook-url
, it can be generated as mentioned in the documentation.
Slack
- Value for
platformName
will beslack
. - All the messages will be dumped as threads of the message for a given date.
- A message will be created with the text as
Logs for Date: dd-MM-yyyy
. This helps to organise the messages grouped by the Date they are sent. - Following configurations will be needed to enable this:
- Create a Slack App referring this. Choose to build from scratch and select the desired workspace.
- For getting
slack-token
:- After the app is created, from the Left Navigation Menu, goto
OAuth and Permissions
tab - Under the Scopes section, add
channels:read
,channels:history
,chat:write
permissions. - Once done, from the same tab, from the
OAuth Tokens
section generate & copyBot User OAuth Token
and install/reinstall it to the workspace. Select the needfulpublic
channel. - Use this generated token as
slack-token
in the configuration of WinstonChannelLogger's object.
- After the app is created, from the Left Navigation Menu, goto
- For getting
slack-channel-id
:- Go to Slack App, from the list of channels, right click on the Public channel for which logger is enabled (same that is allowed in previous step), and select
View channel details
. - Scroll down in popup to get the Channel Id something as shown below:
- Go to Slack App, from the list of channels, right click on the Public channel for which logger is enabled (same that is allowed in previous step), and select
Discord
- Value for
platformName
will bediscord
. - For getting
discord-webhook-url
, it can be generated as mentioned in the documentation.
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or a pull request in this repository.
License
This project is licensed under the GNU GENERAL PUBLIC LICENSE.