1.0.4 • Published 3 years ago
@kevit/winston-channel-logger v1.0.4
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-loggeror
yarn add @kevit/winston-channel-loggerUsage
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
WinstonChannelLoggeras:
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
transportsarray ofcreateLoggerFor 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
platformNamewill bems-teams. - For getting
teams-webhook-url, it can be generated as mentioned in the documentation.
Slack
- Value for
platformNamewill 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 Permissionstab - Under the Scopes section, add
channels:read,channels:history,chat:writepermissions. - Once done, from the same tab, from the
OAuth Tokenssection generate & copyBot User OAuth Tokenand install/reinstall it to the workspace. Select the needfulpublicchannel. - Use this generated token as
slack-tokenin 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
platformNamewill 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.