1.0.4 • Published 11 months ago

@kevit/winston-channel-logger v1.0.4

Weekly downloads
-
License
GNU GENERAL PUBLI...
Repository
github
Last release
11 months ago

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:

  1. Import it into your code as:
import { WinstonChannelLogger } from '@kevit/winston-channel-logger';
  1. 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>',
    }],
});
  1. Finally, attach this custom logger in transports array of createLogger 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 be ms-teams.
  • For getting teams-webhook-url , it can be generated as mentioned in the documentation.

Slack

  • Value for platformName will be slack.
  • 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 & copy Bot User OAuth Token and install/reinstall it to the workspace. Select the needful public channel.
      • Use this generated token as slack-token in the configuration of WinstonChannelLogger's object.
    • 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: Channel Id

Discord

  • Value for platformName will be discord.
  • 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.