Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

winston-telegram

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

winston-telegram

A Telegram transport for winston

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
decreased by-16.06%
Maintainers
1
Weekly downloads
 
Created
Source

winston-telegram

NPM

A Telegram transport for winston.

Installation

$ npm install winston
$ npm install winston-telegram

Usage

var winston = require('winston');

/*
 * Requiring `winston-telegram` will expose
 * `winston.transports.Telegram`
 */
require('winston-telegram').Telegram;

winston.add(winston.transports.Telegram, options);

Options are the following:

  • token: The Telegram bot authentication token. [required]
  • chatId: The chatid you want to send to. [required]
  • level: Level of messages that this transport should log. [optional] [default info]
  • unique: Whether to log only the declared level and none above. [boolean] [optional]
  • silent: Whether to suppress output. [boolean] [optional]
  • disableNotification: Sends the message silently. [boolean] [optional]
  • template: Format output message. [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

Due applying some coding style, you must change these option properties if you're updating from lower versions to >=1.0.0:

  • chatid to chatId
  • disable_notificacion to disableNotification

Examples

Using the Default Logger

var winston = require('winston');

require('winston-telegram').Telegram;

winston.add(winston.transports.Telegram, {
		token : 'TELEGRAM_TOKEN',
		chatId : 'CHAT_ID',
		level : 'error',
		unique : true
    });

winston.log('error', 'Heeere’s Johnny!');

Multiple transports, different chats, different options

var winston = require('winston');

require('winston-telegram').Telegram;

var logger = new (winston.Logger)({
	transports: [
		new (winston.transports.Telegram)({
			name: 'error-channel',
			token : 'TELEGRAM_TOKEN',
			chatId : 'CHAT_ID_1',
			level : 'error',
			unique : true
		}),
		new (winston.transports.Telegram)({
			name: 'info-channel',
			token : 'TELEGRAM_TOKEN',
			chatId : 'CHAT_ID_2',
			level : 'info',
			unique : true,
			disableNotification: true
		})
	]
});

logger.error('All work and no play makes Jack a dull boy.');
logger.info('Come play with us, Danny. Forever... and ever... and ever.');

Using template output:

var winston = require('winston');

require('winston-telegram').Telegram;

winston.add(winston.transports.Telegram, {
		token : 'TELEGRAM_TOKEN',
		chatId : 'CHAT_ID',
		level : 'error',
		unique : true,
		template : '[{level}] [{message}] [{metadata.name}] [{metadata.surname}]'
    });

winston.log('error', 'Redrum. Redrum. Redrum.', { name: 'Danny', surname: 'Torrance' });

//Output: [error] [Redrum. Redrum. Redrum.] [Danny] [Torrance]

Using batching of messages to avoid exceeding rate limits:

var winston = require('winston');

require('winston-telegram').Telegram;

winston.add(winston.transports.Telegram, {
		token : 'TELEGRAM_TOKEN',
		chatId : 'CHAT_ID',
		level : 'info',
		batchingDelay: 1000
});

// first message triggers a new batchingDelay wait
winston.info('First message: '+(new Date()).toString());
// second message is within the batchingDelay wait triggered by the first
// message, so will be batched
winston.info('Second message: '+(new Date()).toString());

setTimeout(function() {
  // third message is also within the wait, so also batched
  winston.info('Third message: '+(new Date()).toString());
}, 500);

setTimeout(function() {
  // fourth message is not within the wait, will be sent separately
  winston.info('Fourth message: '+(new Date()).toString());
}, 1500);

/*
 * Output on Telegram:
 * Sent at 5:22:49PM:
 *   [info] First message: Tue May 30 2017 17:22:47 GMT+0800 (+08)
 *
 *   [info] Second message: Tue May 30 2017 17:22:47 GMT+0800 (+08)
 *
 *   [info] Third message: Tue May 30 2017 17:22:47 GMT+0800 (+08)
 *
 * Sent at 5:22:50PM:
 *   [info] Fourth message: Tue May 30 2017 17:22:48 GMT+0800 (+08)
 */

Change history

v1.2.0 (2017/03/06)

  • #8 Add batching of messages sent within a certain interval (@JustinOng)

v1.1.0 (2017/05/02)

  • #7 Use metadata information in messages (@alberto467)
  • #7 Replace built-in format function by sf node module (@alberto467)
  • Update dependencies

v1.0.0 (2016/12/05)

  • #6 Add optional handleExceptions param (@speedone)
  • Node.js coding style
  • Change option properties for matching coding style

v0.4.0 (2016/09/26)

  • #5 Add message template option
  • Update dependencies
  • Remove peer dependecies

v0.3.0 (2016/07/17)

  • #2 Allow multiple transports, send messages silently
  • Update dependencies

v0.2.1 (2016/03/30)

  • Fix typos

v0.2.0 (2016/03/08)

  • #1 Add log level option

v0.1.0 (2015/11/12)

  • First version

Keywords

FAQs

Package last updated on 03 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc