winston-telegram
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -24,2 +24,6 @@ /* | ||
} | ||
if (options.formatMessage && typeof options.formatMessage !== 'function'){ | ||
throw new Error('winston-telegram \'formatMessage\' property should be function'); | ||
} | ||
this.token = options.token; | ||
@@ -34,2 +38,3 @@ this.chatId = options.chatId; | ||
this.template = options.template || '[{level}] {message}'; | ||
this.formatMessage = options.formatMessage; | ||
this.batchingDelay = options.batchingDelay || 0; | ||
@@ -70,4 +75,11 @@ this.batchingSeparator = options.batchingSeparator || "\n\n"; | ||
var messageText = format(this.template,{level : level, message : msg, metadata : meta}); | ||
var messageText = null; | ||
var formatOptions = {level : level, message : msg, metadata : meta}; | ||
if (this.formatMessage) { | ||
messageText = this.formatMessage(formatOptions) | ||
} else { | ||
messageText = format(this.template, formatOptions) | ||
} | ||
if (this.batchingDelay) { | ||
@@ -74,0 +86,0 @@ this.batchedMessages.push(messageText); |
{ | ||
"name": "winston-telegram", | ||
"description": "A Telegram transport for winston", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"author": "Ivan Marban", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -35,3 +35,4 @@ # winston-telegram | ||
* __disableNotification:__ Sends the message silently. *[boolean]* *[optional]* | ||
* __template:__ Format output message. *[optional]* | ||
* __template:__ Format output message. *[string]* *[optional]* | ||
* __formatMessage:__ Format output message by own method. *[function]* *[optional]* | ||
* __handleExceptions:__ Handle uncaught exceptions. *[boolean]* *[optional]* | ||
@@ -118,2 +119,28 @@ * __batchingDelay:__ Time in ms within which to batch messages together. *[integer]* *[optional]* *[default 0 or disabled]* | ||
Using custom format message: | ||
```js | ||
var winston = require('winston'); | ||
require('winston-telegram').Telegram; | ||
winston.add(winston.transports.Telegram, { | ||
token : 'TELEGRAM_TOKEN', | ||
chatId : 'CHAT_ID', | ||
level : 'error', | ||
unique : true, | ||
formatMessage : function(opts) { | ||
var message = opts.message; | ||
if (opts.level === 'warn') { | ||
message += '[Warning] '; | ||
} | ||
return message; | ||
} | ||
}); | ||
winston.warn('Some warning!!'); | ||
//Output: [Warning] Some warning!! | ||
``` | ||
Using batching of messages to avoid exceeding rate limits: | ||
@@ -164,2 +191,9 @@ ``` js | ||
### v1.3.0 (2018/05/03) | ||
- [#10](https://github.com/ivanmarban/winston-telegram/pull/10) Add formatMessage property ([@noveogroup-amorgunov][6]) | ||
### v1.2.1 (2017/07/26) | ||
- [#9](https://github.com/ivanmarban/winston-telegram/pull/9) Add error description in case of error ([@dutu][5]) | ||
- Update sf library | ||
### v1.2.0 (2017/03/06) | ||
@@ -200,2 +234,4 @@ - [#8](https://github.com/ivanmarban/winston-telegram/pull/8) Add batching of messages sent within a certain interval ([@JustinOng][4]) | ||
[3]: https://github.com/alberto467 | ||
[4]: https://github.com/JustinOng | ||
[4]: https://github.com/JustinOng | ||
[5]: https://github.com/dutu | ||
[6]: https://github.com/noveogroup-amorgunov |
13278
144
233
5