Skip to content

Commit

Permalink
Merge branch 'release/v0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmarban committed Jul 17, 2016
2 parents 6c3ca0c + 809e16a commit 3d671ee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
46 changes: 46 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion lib/winston-telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -16,7 +16,7 @@
"bot"
],
"dependencies": {
"request": "^2.69.0"
"request": "^2.73.0"
},
"devDependencies": {
"winston": ""
Expand Down

0 comments on commit 3d671ee

Please sign in to comment.