winston-telegram
A Telegram transport for winston.
Installation
$ npm install winston
$ npm install winston-telegram
Usage
var winston = require('winston');
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]
String template is based on named arguments:
'{level}' -> level of messages
'{message}' -> text 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}]'
});
winston.log('error', 'Redrum. Redrum. Redrum.');
Change history
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)
v0.2.0 (2016/03/08)
v0.1.0 (2015/11/12)