diff --git a/README.md b/README.md index de9eb9b..82d339d 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,23 @@ A [Telegram][0] transport for [winston][1]. -## Installation +## winston-telegram@2 +Installation: ``` sh -$ npm install winston@2 -$ npm install winston-telegram@1 +$ npm install winston@3 +$ npm install winston-telegram@2 ``` +## Looking for `winston-telegram@1.x` ? +Documentation below is for `winston-telegram@2`. [Read the `winston-telegram@1.x` documentation][8]. + ## Usage ``` js -var winston = require('winston'); +const logger = require('winston'); +const telegramLogger = require('winston-telegram'); -/* - * Requiring `winston-telegram` will expose - * `winston.transports.Telegram` - */ -require('winston-telegram').Telegram; - -winston.add(winston.transports.Telegram, options); +logger.add(new telegramLogger({options})); ``` Options are the following: @@ -53,44 +52,43 @@ Due applying some coding style, you must change these option properties if you'r ## 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!'); +const logger = require('winston'); +const telegramLogger = require('winston-telegram'); + +logger.add(new telegramLogger({ + token: 'TELEGRAM_TOKEN', + chatId: 'CHAT_ID', + level: 'error', + unique: true +})); + +logger.error('Heeere’s Johnny!'); +logger.log({level: 'error', message: '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, - disableNotification: true - }) - ] -}); +const winston = require('winston'); +const telegramLogger = require('winston-telegram'); + +const logger = winston.createLogger({ + transports: [ + new telegramLogger({ + name: 'error-channel', + token: 'TELEGRAM_TOKEN', + chatId: 'CHAT_ID', + level: 'error', + unique: true + }), + new telegramLogger({ + name: 'info-channel', + token: 'TELEGRAM_TOKEN', + chatId: 'CHAT_ID', + level: 'info', + unique: true, + disableNotification: 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.'); @@ -98,76 +96,72 @@ logger.info('Come play with us, Danny. Forever... and ever... and ever.'); Using template output: ``` js -var winston = require('winston'); - -require('winston-telegram').Telegram; +const logger = require('winston'); +const telegramLogger = require('winston-telegram'); -winston.add(winston.transports.Telegram, { - token : 'TELEGRAM_TOKEN', - chatId : 'CHAT_ID', - level : 'error', - unique : true, - template : '[{level}] [{message}] [{metadata.name}] [{metadata.surname}]' - }); +logger.add(new telegramLogger( { + token : 'TELEGRAM_TOKEN', + chatId : 'CHAT_ID', + level : 'error', + unique : true, + template : '[{level}] [{message}] [{metadata.name}] [{metadata.surname}]' +})); -winston.log('error', 'Redrum. Redrum. Redrum.', { name: 'Danny', surname: 'Torrance' }); +logger.log({ level: 'error', message: 'Redrum. Redrum. Redrum.', metadata: { name: 'Danny', surname: 'Torrance' }}); // Output: [error] [Redrum. Redrum. Redrum.] [Danny] [Torrance] ``` 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!!'); +const logger = require('winston'); +const telegramLogger = require('winston-telegram'); + +logger.add(new telegramLogger( { + token : 'TELEGRAM_TOKEN', + chatId : 'CHAT_ID', + level : 'warn', + unique : true, + formatMessage : function(options) { + let message = options.message; + if (options.level === 'warn') { + message = '[Warning] ' + message; + } + return message; + } +})); + +logger.warn('Some warning!!'); // Output: [Warning] Some warning!! ``` Using batching of messages to avoid exceeding rate limits: ``` js -var winston = require('winston'); +const logger = require('winston'); +const telegramLogger = require('winston-telegram'); -require('winston-telegram').Telegram; - -winston.add(winston.transports.Telegram, { - token : 'TELEGRAM_TOKEN', - chatId : 'CHAT_ID', - level : 'info', - batchingDelay: 1000 -}); +logger.add(new telegramLogger( { + token : 'TELEGRAM_TOKEN', + chatId : 'CHAT_ID', + level : 'info', + batchingDelay: 1000 +})); // first message triggers a new batchingDelay wait -winston.info('First message: '+(new Date()).toString()); +logger.info('First message: '+(new Date()).toString()); // second message is within the batchingDelay wait triggered by the first // message, so will be batched -winston.info('Second message: '+(new Date()).toString()); +logger.info('Second message: '+(new Date()).toString()); setTimeout(function() { // third message is also within the wait, so also batched - winston.info('Third message: '+(new Date()).toString()); + logger.info('Third message: '+(new Date()).toString()); }, 500); setTimeout(function() { // fourth message is not within the wait, will be sent separately - winston.info('Fourth message: '+(new Date()).toString()); + logger.info('Fourth message: '+(new Date()).toString()); }, 1500); /* @@ -186,6 +180,9 @@ setTimeout(function() { ## Change history +### v2.0.0 (2019/01/07) +- `winston@3` support + ### v1.3.1 (2019/01/07) - [#12](https://github.com/ivanmarban/winston-telegram/pull/12) Fix comments ([@is2ei][7]) - Update dependencies @@ -235,4 +232,5 @@ setTimeout(function() { [4]: https://github.com/JustinOng [5]: https://github.com/dutu [6]: https://github.com/noveogroup-amorgunov -[7]: https://github.com/is2ei \ No newline at end of file +[7]: https://github.com/is2ei +[8]: https://github.com/ivanmarban/winston-telegram/tree/1.x \ No newline at end of file diff --git a/lib/winston-telegram.js b/lib/winston-telegram.js index 96fd007..fd65788 100644 --- a/lib/winston-telegram.js +++ b/lib/winston-telegram.js @@ -5,10 +5,9 @@ * MIT LICENCE */ -var util = require('util'); -var request = require('request'); -var winston = require('winston'); -var format = require('sf'); +const request = require('request'); +const format = require('sf'); +const Transport = require('winston-transport'); /** * @constructs @@ -16,113 +15,100 @@ var format = require('sf'); * @param {String} options.token Telegram bot authentication token * @param {String} options.chatId Telegram unique identifier for chat */ -var Telegram = exports.Telegram = function (options) { - options = options || {}; - if (!options.token || !options.chatId){ - throw new Error('winston-telegram requires \'token\' and \'chatId\' property'); - } - if (options.formatMessage && typeof options.formatMessage !== 'function'){ - throw new Error('winston-telegram \'formatMessage\' property should be function'); - } - - this.token = options.token; - this.chatId = options.chatId; - this.level = options.level || 'info'; - this.handleExceptions = options.handleExceptions || false; - this.unique = options.unique || false; - this.silent = options.silent || false; - this.disableNotification = options.disableNotification || false; - this.name = options.name || this.name; - this.template = options.template || '[{level}] {message}'; - this.formatMessage = options.formatMessage; - this.batchingDelay = options.batchingDelay || 0; - this.batchingSeparator = options.batchingSeparator || "\n\n"; - - this.batchedMessages = []; - this.batchingTimeout = 0; -}; +module.exports = class Telegram extends Transport { + constructor(options) { + super(options); + options = options || {}; + + if (!options.token || !options.chatId){ + throw new Error('winston-telegram requires \'token\' and \'chatId\' property'); + } + if (options.formatMessage && typeof options.formatMessage !== 'function'){ + throw new Error('winston-telegram \'formatMessage\' property should be function'); + } -/** @extends winston.Transport */ -util.inherits(Telegram, winston.Transport); + this.token = options.token; + this.chatId = options.chatId; + this.level = options.level || 'info'; + this.handleExceptions = options.handleExceptions || false; + this.unique = options.unique || false; + this.silent = options.silent || false; + this.disableNotification = options.disableNotification || false; + this.name = options.name || this.name || 'winston-telegram'; + this.template = options.template || '[{level}] {message}'; + this.formatMessage = options.formatMessage; + this.batchingDelay = options.batchingDelay || 0; + this.batchingSeparator = options.batchingSeparator || "\n\n"; + + this.batchedMessages = []; + this.batchingTimeout = 0; + } -/** - * Define a getter so that `winston.transports.Telegram` - * is available and thus backwards compatible. - */ -winston.transports.Telegram = Telegram; + /** + * Core logging method exposed to Winston. + * @function log + * @param info {Object} info - TODO: add param description. + * @param callback {function} callback - TODO: add param description. + */ + log(info, callback) { + let self = this; + if (this.silent) return callback(null, true); + if (this.unique && this.level != info.level) return callback(null, true); + + let messageText = null; + let formatOptions = {level : info.level, message : info.message, metadata : info.metadata}; + + if (this.formatMessage) { + messageText = this.formatMessage(formatOptions) + } else { + messageText = format(this.template, formatOptions) + } -/** - * Expose the name of this Transport on the prototype - */ -Telegram.prototype.name = 'telegram'; + if (this.batchingDelay) { + this.batchedMessages.push(messageText); -/** - * Core logging method exposed to Winston. - * @function log - * @member Telegram - * @param {string} level Level at which to log the message - * @param {string} msg Message to log - * @param {Object} meta **Optional** Additional metadata to attach - * @param {function} callback Continuation to respond to when complete. - */ -Telegram.prototype.log = function (level, msg, meta, callback) { - var self = this; - if (this.silent) return callback(null, true); - if (this.unique && this.level != level) return callback(null, true); + if (!this.batchingTimeout) { + this.batchingTimeout = setTimeout(function() { + let combinedMessages = self.batchedMessages.join(self.batchingSeparator); + self.send(combinedMessages); - var messageText = null; - var formatOptions = {level : level, message : msg, metadata : meta}; + self.batchedMessages = []; + self.batchingTimeout = 0; + }, this.batchingDelay); + } + } + else { + self.send(messageText); + } - if (this.formatMessage) { - messageText = this.formatMessage(formatOptions) - } else { - messageText = format(this.template, formatOptions) + callback(null, true); } - if (this.batchingDelay) { - this.batchedMessages.push(messageText); - - if (!this.batchingTimeout) { - this.batchingTimeout = setTimeout(function() { - var combinedMessages = self.batchedMessages.join(self.batchingSeparator); - self.send(combinedMessages); - - self.batchedMessages = []; - self.batchingTimeout = 0; - }, this.batchingDelay); - } - } - else { - self.send(messageText); + /** + * Actual method that sends the given message to Telegram. + * @function send + * @param messageText {string} formatted text to log. + */ + send(messageText) { + let self = this; + + request({ + url : 'https://api.telegram.org/bot'+this.token+'/sendMessage', + method : 'POST', + json : { + chat_id : this.chatId, + text : messageText, + disable_notification : this.disableNotification + } + }, function(error, response, body){ + if (error) { + self.emit('error', error); + } + if (response && response.statusCode != 200) { + self.emit('error', response.statusCode + (body && body.description && (': ' + body.description) || '')); + } + self.emit('logged'); + }); } - callback(null, true); -}; - -/** - * Actual method that sends the given message to Telegram - * @function send - * @member Telegram - * @param {string} messageText Formatted text to log - */ -Telegram.prototype.send = function (messageText) { - var self = this; - - request({ - url : 'https://api.telegram.org/bot'+this.token+'/sendMessage', - method : 'POST', - json : { - chat_id : this.chatId, - text : messageText, - disable_notification : this.disableNotification - } - }, function(error, response, body){ - if (error) { - self.emit('error', error); - } - if (response && response.statusCode != 200) { - self.emit('error', response.statusCode + (body && body.description && (': ' + body.description) || '')); - } - self.emit('logged'); - }); -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 39f7941..f5ab7d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "winston-telegram", - "version": "1.3.1", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -125,10 +125,13 @@ "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" }, "async": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz", - "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k=", - "dev": true + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", + "integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==", + "dev": true, + "requires": { + "lodash": "^4.17.10" + } }, "asynckit": { "version": "0.4.0", @@ -145,11 +148,6 @@ "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz", "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, "bcrypt-pbkdf": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", @@ -158,15 +156,6 @@ "tweetnacl": "^0.14.3" } }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -181,12 +170,63 @@ "lazy-cache": "^1.0.3" } }, + "color": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/color/-/color-3.0.0.tgz", + "integrity": "sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w==", + "dev": true, + "requires": { + "color-convert": "^1.9.1", + "color-string": "^1.5.2" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, + "color-string": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.5.3.tgz", + "integrity": "sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw==", + "dev": true, + "requires": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, + "colornames": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/colornames/-/colornames-1.1.1.tgz", + "integrity": "sha1-+IiQMGhcfE/54qVZ9Qd+t2qBb5Y=", + "dev": true + }, "colors": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", - "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.3.3.tgz", + "integrity": "sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg==", "dev": true }, + "colorspace": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/colorspace/-/colorspace-1.1.1.tgz", + "integrity": "sha512-pI3btWyiuz7Ken0BWh9Elzsmv2bM9AhA7psXib4anUXy/orfZ/E0MbQwhSOG/9L8hLlalqrU0UhOuqxW1YjmVw==", + "dev": true, + "requires": { + "color": "3.0.x", + "text-hex": "1.0.x" + } + }, "combined-stream": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", @@ -195,22 +235,11 @@ "delayed-stream": "~1.0.0" } }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, - "cycle": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz", - "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=", - "dev": true - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -224,10 +253,16 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, - "diff": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/diff/-/diff-1.0.8.tgz", - "integrity": "sha1-NDJ2MI7Jkbe8giZ+1VvBQR+XFmY=" + "diagnostics": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/diagnostics/-/diagnostics-1.1.1.tgz", + "integrity": "sha512-8wn1PmdunLJ9Tqbx+Fx/ZEuHfJf4NKSN2ZBj7SJC/OWRWha843+WsTjqMe1B5E3p28jqBlp+mJ2fPVxPyNgYKQ==", + "dev": true, + "requires": { + "colorspace": "1.1.x", + "enabled": "1.0.x", + "kuler": "1.0.x" + } }, "ecc-jsbn": { "version": "0.1.2", @@ -238,6 +273,21 @@ "safer-buffer": "^2.1.0" } }, + "enabled": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz", + "integrity": "sha1-ll9lE9LC0cX0ZStkouM5ZGf8L5M=", + "dev": true, + "requires": { + "env-variable": "0.0.x" + } + }, + "env-variable": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/env-variable/-/env-variable-0.0.5.tgz", + "integrity": "sha512-zoB603vQReOFvTg5xMl9I1P2PnHsHQQKTEowsKKD7nseUfJq6UWzK+4YtlWUO1nhiQUxe6XMkk+JleSZD1NZFA==", + "dev": true + }, "export-dirs": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/export-dirs/-/export-dirs-0.2.4.tgz", @@ -261,11 +311,6 @@ "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, - "eyes": { - "version": "0.1.8", - "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz", - "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=" - }, "fast-deep-equal": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", @@ -276,6 +321,18 @@ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, + "fast-safe-stringify": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.6.tgz", + "integrity": "sha512-q8BZ89jjc+mz08rSxROs8VsrBBcn1SIw1kq9NjolL509tkABRk9io01RAjSaEv1Xb2uFLt8VtRiZbGp5H8iDtg==", + "dev": true + }, + "fecha": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fecha/-/fecha-2.3.3.tgz", + "integrity": "sha512-lUGBnIamTAwk4znq5BcqsDaxSmZ9nDVJaij6NvRt/Tg4R69gERA+otPKbS86ROw9nxVMw2/mp1fnaiWqbs6Sdg==", + "dev": true + }, "for-in": { "version": "0.1.8", "resolved": "https://registry.npmjs.org/for-in/-/for-in-0.1.8.tgz", @@ -311,11 +368,6 @@ "mime-types": "^2.1.12" } }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -324,19 +376,6 @@ "assert-plus": "^1.0.0" } }, - "glob": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, "har-schema": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", @@ -366,19 +405,17 @@ "sshpk": "^1.7.0" } }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==", + "dev": true }, "is-buffer": { "version": "1.1.6", @@ -416,11 +453,23 @@ "isobject": "^3.0.1" } }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", + "dev": true + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, + "isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "dev": true + }, "isobject": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", @@ -470,11 +519,39 @@ "is-buffer": "^1.0.2" } }, + "kuler": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/kuler/-/kuler-1.0.1.tgz", + "integrity": "sha512-J9nVUucG1p/skKul6DU3PUZrhs0LPulNaeUOox0IyXDi8S4CztTHs1gQphhuZmzXG7VOQSf6NJfKuzteQLv9gQ==", + "dev": true, + "requires": { + "colornames": "^1.1.1" + } + }, "lazy-cache": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-1.0.4.tgz", "integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=" }, + "lodash": { + "version": "4.17.11", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", + "dev": true + }, + "logform": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/logform/-/logform-1.10.0.tgz", + "integrity": "sha512-em5ojIhU18fIMOw/333mD+ZLE2fis0EzXl1ZwHx4iQzmpQi6odNiY/t+ITNr33JZhT9/KEaH+UPIipr6a9EjWg==", + "dev": true, + "requires": { + "colors": "^1.2.1", + "fast-safe-stringify": "^2.0.4", + "fecha": "^2.3.3", + "ms": "^2.1.1", + "triple-beam": "^1.2.0" + } + }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -511,13 +588,11 @@ "mime-db": "~1.37.0" } }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "^1.1.7" - } + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true }, "oauth-sign": { "version": "0.9.0", @@ -586,24 +661,23 @@ "for-own": "^0.1.3" } }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "one-time": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz", + "integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4=", + "dev": true }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "process-nextick-args": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", + "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "dev": true + }, "psl": { "version": "1.1.31", "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", @@ -619,6 +693,21 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, + "readable-stream": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "dev": true, + "requires": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, "repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", @@ -677,6 +766,15 @@ "utils": "^0.3.1" } }, + "simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", + "dev": true, + "requires": { + "is-arrayish": "^0.3.1" + } + }, "sshpk": { "version": "1.16.0", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.0.tgz", @@ -699,11 +797,26 @@ "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=", "dev": true }, + "string_decoder": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, + "requires": { + "safe-buffer": "~5.1.0" + } + }, "striptags": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/striptags/-/striptags-2.2.1.tgz", "integrity": "sha1-TEULcI1BuL85zyTEn/I0/Gqr/TI=" }, + "text-hex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz", + "integrity": "sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==", + "dev": true + }, "tough-cookie": { "version": "2.4.3", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz", @@ -720,6 +833,12 @@ } } }, + "triple-beam": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/triple-beam/-/triple-beam-1.3.0.tgz", + "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==", + "dev": true + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -741,6 +860,12 @@ "punycode": "^2.1.0" } }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "dev": true + }, "utils": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/utils/-/utils-0.3.1.tgz", @@ -789,39 +914,37 @@ "extsprintf": "^1.2.0" } }, - "vows": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/vows/-/vows-0.8.2.tgz", - "integrity": "sha1-aR95qybM3oC6cm3en+yOc9a88us=", - "requires": { - "diff": "~1.0.8", - "eyes": "~0.1.6", - "glob": "^7.1.2" - } - }, "winston": { - "version": "2.4.4", - "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.4.tgz", - "integrity": "sha512-NBo2Pepn4hK4V01UfcWcDlmiVTs7VTB1h7bgnB0rgP146bYhMxX0ypCz3lBOfNxCO4Zuek7yeT+y/zM1OfMw4Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/winston/-/winston-3.1.0.tgz", + "integrity": "sha512-FsQfEE+8YIEeuZEYhHDk5cILo1HOcWkGwvoidLrDgPog0r4bser1lEIOco2dN9zpDJ1M88hfDgZvxe5z4xNcwg==", "dev": true, "requires": { - "async": "~1.0.0", - "colors": "1.0.x", - "cycle": "1.0.x", - "eyes": "0.1.x", - "isstream": "0.1.x", - "stack-trace": "0.0.x" + "async": "^2.6.0", + "diagnostics": "^1.1.1", + "is-stream": "^1.1.0", + "logform": "^1.9.1", + "one-time": "0.0.4", + "readable-stream": "^2.3.6", + "stack-trace": "0.0.x", + "triple-beam": "^1.3.0", + "winston-transport": "^4.2.0" + } + }, + "winston-transport": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/winston-transport/-/winston-transport-4.3.0.tgz", + "integrity": "sha512-B2wPuwUi3vhzn/51Uukcao4dIduEiPOcOt9HJ3QeaXgkJ5Z7UwpBzxS4ZGNHtrxrUvTwemsQiSys0ihOf8Mp1A==", + "dev": true, + "requires": { + "readable-stream": "^2.3.6", + "triple-beam": "^1.2.0" } }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==" - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" } } } diff --git a/package.json b/package.json index fb8fb75..c975a6f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "winston-telegram", "description": "A Telegram transport for winston", - "version": "1.3.1", + "version": "2.0.0", "author": "Ivan Marban", "repository": { "type": "git", @@ -20,13 +20,9 @@ "sf": "^0.2.0" }, "devDependencies": { - "winston": "2.4.4", - "vows": "" + "winston": "^3.0.0" }, "main": "./lib/winston-telegram", - "scripts": { - "test": "vows test/*test.js --spec" - }, "engines": { "node": ">= 0.10.0" }, diff --git a/test/winston-telegram-test.js b/test/winston-telegram-test.js deleted file mode 100644 index fc2429a..0000000 --- a/test/winston-telegram-test.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - * winston-telegram-test.js: Tests for instances of the Telegram transport - * - * (C) 2015 Ivan Marban - * MIT LICENSE - */ -var vows = require('vows'), - assert = require('assert'), - winston = require('winston'), - helpers = require('winston/test/helpers'), - Telegram = require('../lib/winston-telegram').Telegram; - -var TelegramTransport; - -TelegramTransport = new(Telegram)({ - token: '177492804:AAG318J_PjC03-okUmqQV652EDbf_Rr0vTo', - chatId: '-50115750' -}); - -function assertTelegram(transport) { - assert.instanceOf(transport, Telegram); - assert.isFunction(transport.log); -} - -vows.describe('winston-telegram').addBatch({ - 'An instance of the Telegram Transport': { - 'when passed an options': { - 'should have the proper methods defined': function() { - assertTelegram(TelegramTransport); - }, - 'the log() method': helpers.testNpmLevels(TelegramTransport, 'should log messages to Telegram', function(ign, err, logged) { - assert.isNull(err); - assert.isTrue(logged); - }) - } - } -}).export(module); \ No newline at end of file