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]
- disable_notification: Sends the message silently. [boolean] [optional]
- template: Format output message. [optional]
String template is based on named arguments:
'{level}' -> level of messages
'{message}' -> text of messages
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,
disable_notification: 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.');