@wildegor/winston-telegram
v1.1.6
Published
A Telegram Transport for Winston
Downloads
6
Maintainers
Readme
Winston-Telegram
A Telegram transport for winston.
Originally forked from ivanmarban/winston-telegram and updated to support winston 3.x and new features.
Main features:
- [x] Send log message to Telegram;
- [x] Send log messages with batching delay;
- [x] Send log messages with custom template;
- [x] Send log messages with custom formatMessage function;
- [x] Send log messages to specific chat;
- [x] Send log messages to specific topic;
- [x] Send log messages with silent mode;
- [x] Send log messages with disable notification;
- [x] Send log messages with custom parse mode;
- [x] Send log messages with custom levels;
- [x] Send log messages with handle exceptions;
- [x] Send log messages with custom batching separator.
Installation:
$ yarn add winston@3
$ yarn add winston-transport@4
$ yarn add axios
$ yarn add @wildegor/winston-telegram@latest
Usage
const logger = require('winston')
const TelegramTransport = require('@wildegor/winston-telegram')
// or
import { TelegramTransport } from '@wildegor/winston-telegram';
logger.add(new TelegramTransport(options))
Options:
- token: The Telegram bot authentication token. [required]
- chatId: The Telegram chatid you want to send to. [optional]
- parseMode: The Telegram mode for parsing entities in the message text. See formatting options for more details. [optional]
- levels: Levels of messages that this transport should log. [optional] [default ALL]
- silent: Whether to suppress output. [boolean] [optional]
- disableNotification: Sends the message silently. [boolean] [optional]
- template: Format output message. [string] [optional]
- formatMessage: Format output message by own method. [function] [optional]
- handleExceptions: Handle uncaught exceptions. [boolean] [optional]
- batchingDelay: Time in ms within which to batch messages together. [integer] [optional] [default 0 or disabled]
- batchingSeparator: String with which to join batched messages with [string] [default "\n\n"]
String template is based on named arguments:
'{level}' -> level of messages
'{message}' -> text of messages
'{metadata}' -> metadata object of messages
Examples
Follow below steps to run the examples:
$ git clone [email protected]:wildegor/winston-telegram.git -b main --single-branch
$ yarn install
Replace TELEGRAM_TOKEN
and CHAT_ID
with appropriate values, then run whatever example you want:
$ cd examples/simple-log # or examples/replace-nest-logger
$ yarn install
$ yarn start:dev