diff --git a/README.md b/README.md index 5ca3042..f97f60c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # winston-telegram +[![NPM](https://nodei.co/npm/winston-telegram.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/winston-telegram/) + A [Telegram][0] transport for [winston][1]. ## Installation @@ -26,6 +28,10 @@ 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]* + [0]: https://telegram.org/ [1]: https://github.com/flatiron/winston \ No newline at end of file diff --git a/lib/winston-telegram.js b/lib/winston-telegram.js index dd5cb92..d6469ae 100644 --- a/lib/winston-telegram.js +++ b/lib/winston-telegram.js @@ -22,6 +22,9 @@ var Telegram = exports.Telegram = function (options) { } this.token = options.token this.chatid = options.chatid; + this.level = options.level || 'info'; + this.unique = options.unique || false; + this.silent = options.silent || false; }; /** @extends winston.Transport */ @@ -44,9 +47,9 @@ util.inherits(Telegram, winston.Transport); */ Telegram.prototype.log = function (level, msg, meta, callback) { var self = this; - if (this.silent) { - return callback && callback(null, true); - } + if (this.silent) return callback(null, true); + if (this.unique && this.level != level) return callback(null, true); + request({ url : 'https://api.telegram.org/bot'+this.token+'/sendMessage', method : 'POST', diff --git a/package.json b/package.json index 24760d7..91e8473 100644 --- a/package.json +++ b/package.json @@ -1,32 +1,36 @@ { - "name": "winston-telegram", - "description": "A Telegram transport for winston", - "version": "0.1.0", - "author": "Ivan Marban", - "repository": { - "type": "git", - "url": "http://github.com/ivanmarban/winston-telegram.git" - }, - "keywords": ["logging", - "sysadmin", - "tools", - "winston", - "telegram", - "bot"], - "dependencies": { - "request": "^2.65.0" - }, - "devDependencies": { - "winston": "" - }, - "peerDependencies": { - "winston": "", - "vows": "" - }, - "main": "./lib/winston-telegram", - "scripts": { "test": "vows test/*test.js --spec" }, - "engines": { - "node": ">= 0.10.0" - }, - "license": "MIT" -} \ No newline at end of file + "name": "winston-telegram", + "description": "A Telegram transport for winston", + "version": "0.2.0", + "author": "Ivan Marban", + "repository": { + "type": "git", + "url": "http://github.com/ivanmarban/winston-telegram.git" + }, + "keywords": [ + "logging", + "sysadmin", + "tools", + "winston", + "telegram", + "bot" + ], + "dependencies": { + "request": "^2.69.0" + }, + "devDependencies": { + "winston": "" + }, + "peerDependencies": { + "winston": "", + "vows": "" + }, + "main": "./lib/winston-telegram", + "scripts": { + "test": "vows test/*test.js --spec" + }, + "engines": { + "node": ">= 0.10.0" + }, + "license": "MIT" +}