From 87d7f6732524beeedf5e177fe6e192914954a542 Mon Sep 17 00:00:00 2001 From: Ivan Marban Date: Sun, 17 Jul 2016 17:25:55 +0200 Subject: [PATCH 1/4] Allow multiple transports, send messages silently --- lib/winston-telegram.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/winston-telegram.js b/lib/winston-telegram.js index 56e86a3..5c0cc49 100644 --- a/lib/winston-telegram.js +++ b/lib/winston-telegram.js @@ -25,6 +25,8 @@ var Telegram = exports.Telegram = function (options) { this.level = options.level || 'info'; this.unique = options.unique || false; this.silent = options.silent || false; + this.disable_notification = options.disable_notification || false; + this.name = options.name || this.name; }; /** @extends winston.Transport */ @@ -36,6 +38,11 @@ util.inherits(Telegram, winston.Transport); */ winston.transports.Telegram = Telegram; +/** + * Expose the name of this Transport on the prototype + */ +Telegram.prototype.name = 'telegram'; + /** * Core logging method exposed to Winston. * @function log @@ -55,7 +62,8 @@ Telegram.prototype.log = function (level, msg, meta, callback) { method : 'POST', json : { chat_id : this.chatid, - text : '['+level+'] '+msg + text : '['+level+'] '+msg, + disable_notification : this.disable_notification } }, function(error, response, body){ if (error) { From 952d49833a7802f7fc3f00afdafa754403d2b5ca Mon Sep 17 00:00:00 2001 From: Ivan Marban Date: Sun, 17 Jul 2016 17:26:09 +0200 Subject: [PATCH 2/4] Update dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d450ef..d5a215e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "bot" ], "dependencies": { - "request": "^2.69.0" + "request": "^2.73.0" }, "devDependencies": { "winston": "" From 90849d6cbea62b787191272d478838d5a3ba167d Mon Sep 17 00:00:00 2001 From: Ivan Marban Date: Sun, 17 Jul 2016 17:26:36 +0200 Subject: [PATCH 3/4] Update README with examples --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index f97f60c..b91b80d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,53 @@ Options are the following: * __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]* +## Examples +Using the Default Logger +``` js +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 +``` js +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.'); +``` [0]: https://telegram.org/ [1]: https://github.com/flatiron/winston \ No newline at end of file From 809e16ad43900ca87d589e875e13557380b2c854 Mon Sep 17 00:00:00 2001 From: Ivan Marban Date: Sun, 17 Jul 2016 17:31:03 +0200 Subject: [PATCH 4/4] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d5a215e..b97ce0a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "winston-telegram", "description": "A Telegram transport for winston", - "version": "0.2.1", + "version": "0.3.0", "author": "Ivan Marban", "repository": { "type": "git",