winston-aws-cloudwatch
Advanced tools
Comparing version 1.6.0 to 2.0.0
@@ -11,10 +11,6 @@ 'use strict'; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _debug2 = require('debug'); | ||
@@ -28,10 +24,2 @@ | ||
var _defaults = require('defaults'); | ||
var _defaults2 = _interopRequireDefault(_defaults); | ||
var _lodash = require('lodash.find'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _cloudwatchEventFormatter = require('./cloudwatch-event-formatter'); | ||
@@ -43,21 +31,21 @@ | ||
var debug = (0, _debug3.default)('winston-aws-cloudwatch:CloudWatchClient'); | ||
const debug = (0, _debug3.default)('winston-aws-cloudwatch:CloudWatchClient'); | ||
var CloudWatchClient = function () { | ||
function CloudWatchClient(logGroupName, logStreamName, options) { | ||
(0, _classCallCheck3.default)(this, CloudWatchClient); | ||
const DEFAULT_OPTIONS = { | ||
awsConfig: null, | ||
formatLog: null, | ||
formatLogItem: null, | ||
createLogGroup: false, | ||
createLogStream: false, | ||
submissionRetryCount: 1 | ||
}; | ||
class CloudWatchClient { | ||
constructor(logGroupName, logStreamName, options) { | ||
debug('constructor', { logGroupName, logStreamName, options }); | ||
this._logGroupName = logGroupName; | ||
this._logStreamName = logStreamName; | ||
this._options = (0, _defaults2.default)(options, { | ||
awsConfig: null, | ||
maxSequenceTokenAge: -1, | ||
formatLog: null, | ||
formatLogItem: null, | ||
createLogGroup: false, | ||
createLogStream: false | ||
}); | ||
this._options = (0, _assign2.default)({}, DEFAULT_OPTIONS, options); | ||
this._formatter = new _cloudwatchEventFormatter2.default(this._options); | ||
this._sequenceTokenInfo = null; | ||
this._sequenceToken = null; | ||
this._client = new _awsSdk2.default.CloudWatchLogs(this._options.awsConfig); | ||
@@ -67,141 +55,106 @@ this._initializing = null; | ||
(0, _createClass3.default)(CloudWatchClient, [{ | ||
key: 'submit', | ||
value: function submit(batch) { | ||
var _this = this; | ||
submit(batch) { | ||
debug('submit', { batch }); | ||
return this._initialize().then(() => this._doSubmit(batch, 0)); | ||
} | ||
debug('submit', { batch }); | ||
return this._initialize().then(function () { | ||
return _this._getSequenceToken(); | ||
}).then(function (sequenceToken) { | ||
return _this._putLogEvents(batch, sequenceToken); | ||
}).then(function (_ref) { | ||
var nextSequenceToken = _ref.nextSequenceToken; | ||
return _this._storeSequenceToken(nextSequenceToken); | ||
}); | ||
_initialize() { | ||
if (this._initializing == null) { | ||
this._initializing = this._maybeCreateLogGroup().then(() => this._maybeCreateLogStream()); | ||
} | ||
}, { | ||
key: '_initialize', | ||
value: function _initialize() { | ||
var _this2 = this; | ||
return this._initializing; | ||
} | ||
if (this._initializing == null) { | ||
this._initializing = this._maybeCreateLogGroup().then(function () { | ||
return _this2._maybeCreateLogStream(); | ||
}); | ||
} | ||
return this._initializing; | ||
_maybeCreateLogGroup() { | ||
if (!this._options.createLogGroup) { | ||
return _promise2.default.resolve(); | ||
} | ||
}, { | ||
key: '_maybeCreateLogGroup', | ||
value: function _maybeCreateLogGroup() { | ||
var _this3 = this; | ||
const params = { | ||
logGroupName: this._logGroupName | ||
}; | ||
return this._client.createLogGroup(params).promise().catch(err => this._allowResourceAlreadyExistsException(err)); | ||
} | ||
if (!this._options.createLogGroup) { | ||
return _promise2.default.resolve(); | ||
} | ||
var params = { | ||
logGroupName: this._logGroupName | ||
}; | ||
return this._client.createLogGroup(params).promise().catch(function (err) { | ||
return _this3._allowResourceAlreadyExistsException(err); | ||
}); | ||
_maybeCreateLogStream() { | ||
if (!this._options.createLogStream) { | ||
return _promise2.default.resolve(); | ||
} | ||
}, { | ||
key: '_maybeCreateLogStream', | ||
value: function _maybeCreateLogStream() { | ||
var _this4 = this; | ||
const params = { | ||
logGroupName: this._logGroupName, | ||
logStreamName: this._logStreamName | ||
}; | ||
return this._client.createLogStream(params).promise().catch(err => this._allowResourceAlreadyExistsException(err)); | ||
} | ||
if (!this._options.createLogStream) { | ||
return _promise2.default.resolve(); | ||
} | ||
var params = { | ||
logGroupName: this._logGroupName, | ||
logStreamName: this._logStreamName | ||
}; | ||
return this._client.createLogStream(params).promise().catch(function (err) { | ||
return _this4._allowResourceAlreadyExistsException(err); | ||
}); | ||
} | ||
}, { | ||
key: '_allowResourceAlreadyExistsException', | ||
value: function _allowResourceAlreadyExistsException(err) { | ||
if (err.code !== 'ResourceAlreadyExistsException') { | ||
throw err; | ||
} | ||
} | ||
}, { | ||
key: '_putLogEvents', | ||
value: function _putLogEvents(batch, sequenceToken) { | ||
var _this5 = this; | ||
_allowResourceAlreadyExistsException(err) { | ||
return err.code === 'ResourceAlreadyExistsException' ? _promise2.default.resolve() : _promise2.default.reject(err); | ||
} | ||
debug('putLogEvents', { batch, sequenceToken }); | ||
var params = { | ||
logGroupName: this._logGroupName, | ||
logStreamName: this._logStreamName, | ||
logEvents: batch.map(function (item) { | ||
return _this5._formatter.formatLogItem(item); | ||
}), | ||
sequenceToken | ||
}; | ||
return this._client.putLogEvents(params).promise(); | ||
} | ||
}, { | ||
key: '_getSequenceToken', | ||
value: function _getSequenceToken() { | ||
var now = +new Date(); | ||
var isStale = !this._sequenceTokenInfo || this._sequenceTokenInfo.date + this._options.maxSequenceTokenAge < now; | ||
return isStale ? this._fetchAndStoreSequenceToken() : _promise2.default.resolve(this._sequenceTokenInfo.sequenceToken); | ||
} | ||
}, { | ||
key: '_fetchAndStoreSequenceToken', | ||
value: function _fetchAndStoreSequenceToken() { | ||
var _this6 = this; | ||
_doSubmit(batch, retryCount) { | ||
return this._maybeUpdateSequenceToken().then(() => this._putLogEventsAndStoreSequenceToken(batch)).catch(err => this._handlePutError(err, batch, retryCount)); | ||
} | ||
debug('fetchSequenceToken'); | ||
return this._findLogStream().then(function (_ref2) { | ||
var uploadSequenceToken = _ref2.uploadSequenceToken; | ||
return _this6._storeSequenceToken(uploadSequenceToken); | ||
}); | ||
_maybeUpdateSequenceToken() { | ||
return this._sequenceToken != null ? _promise2.default.resolve() : this._fetchAndStoreSequenceToken(); | ||
} | ||
_handlePutError(err, batch, retryCount) { | ||
if (err.code !== 'InvalidSequenceTokenException') { | ||
return _promise2.default.reject(err); | ||
} | ||
}, { | ||
key: '_storeSequenceToken', | ||
value: function _storeSequenceToken(sequenceToken) { | ||
debug('storeSequenceToken', { sequenceToken }); | ||
var date = +new Date(); | ||
this._sequenceTokenInfo = { sequenceToken, date }; | ||
return sequenceToken; | ||
if (retryCount >= this._options.submissionRetryCount) { | ||
const error = new Error('Invalid sequence token, will retry'); | ||
error.code = 'InvalidSequenceTokenException'; | ||
return _promise2.default.reject(error); | ||
} | ||
}, { | ||
key: '_findLogStream', | ||
value: function _findLogStream(nextToken) { | ||
var _this7 = this; | ||
this._sequenceToken = null; | ||
return this._doSubmit(batch, retryCount + 1); | ||
} | ||
debug('findLogStream', { nextToken }); | ||
var params = { | ||
logGroupName: this._logGroupName, | ||
logStreamNamePrefix: this._logStreamName, | ||
nextToken | ||
}; | ||
return this._client.describeLogStreams(params).promise().then(function (_ref3) { | ||
var logStreams = _ref3.logStreams, | ||
nextToken = _ref3.nextToken; | ||
_putLogEventsAndStoreSequenceToken(batch) { | ||
return this._putLogEvents(batch).then(({ nextSequenceToken }) => this._storeSequenceToken(nextSequenceToken)); | ||
} | ||
var match = (0, _lodash2.default)(logStreams, function (_ref4) { | ||
var logStreamName = _ref4.logStreamName; | ||
return logStreamName === _this7._logStreamName; | ||
}); | ||
if (match) { | ||
return match; | ||
} | ||
if (nextToken == null) { | ||
throw new Error('Log stream not found'); | ||
} | ||
return _this7._findLogStream(nextToken); | ||
}); | ||
} | ||
}]); | ||
return CloudWatchClient; | ||
}(); | ||
_putLogEvents(batch) { | ||
const sequenceToken = this._sequenceToken; | ||
debug('putLogEvents', { batch, sequenceToken }); | ||
const params = { | ||
logGroupName: this._logGroupName, | ||
logStreamName: this._logStreamName, | ||
logEvents: batch.map(item => this._formatter.formatLogItem(item)), | ||
sequenceToken | ||
}; | ||
return this._client.putLogEvents(params).promise(); | ||
} | ||
_fetchAndStoreSequenceToken() { | ||
debug('fetchSequenceToken'); | ||
return this._findLogStream().then(({ uploadSequenceToken }) => this._storeSequenceToken(uploadSequenceToken)); | ||
} | ||
_storeSequenceToken(sequenceToken) { | ||
debug('storeSequenceToken', { sequenceToken }); | ||
this._sequenceToken = sequenceToken; | ||
return sequenceToken; | ||
} | ||
_findLogStream(nextToken) { | ||
debug('findLogStream', { nextToken }); | ||
const params = { | ||
logGroupName: this._logGroupName, | ||
logStreamNamePrefix: this._logStreamName, | ||
nextToken | ||
}; | ||
return this._client.describeLogStreams(params).promise().then(({ logStreams, nextToken }) => { | ||
const match = logStreams.find(({ logStreamName }) => logStreamName === this._logStreamName); | ||
if (match) { | ||
return match; | ||
} | ||
if (nextToken == null) { | ||
throw new Error('Log stream not found'); | ||
} | ||
return this._findLogStream(nextToken); | ||
}); | ||
} | ||
} | ||
exports.default = CloudWatchClient; |
@@ -11,10 +11,2 @@ 'use strict'; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _lodash = require('lodash.isempty'); | ||
@@ -26,10 +18,4 @@ | ||
var CloudWatchEventFormatter = function () { | ||
function CloudWatchEventFormatter() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
formatLog = _ref.formatLog, | ||
formatLogItem = _ref.formatLogItem; | ||
(0, _classCallCheck3.default)(this, CloudWatchEventFormatter); | ||
class CloudWatchEventFormatter { | ||
constructor({ formatLog, formatLogItem } = {}) { | ||
if (typeof formatLog === 'function') { | ||
@@ -42,20 +28,14 @@ this.formatLog = formatLog; | ||
(0, _createClass3.default)(CloudWatchEventFormatter, [{ | ||
key: 'formatLogItem', | ||
value: function formatLogItem(item) { | ||
return { | ||
message: this.formatLog(item), | ||
timestamp: item.date | ||
}; | ||
} | ||
}, { | ||
key: 'formatLog', | ||
value: function formatLog(item) { | ||
var meta = (0, _lodash2.default)(item.meta) ? '' : ' ' + (0, _stringify2.default)(item.meta, null, 2); | ||
return `[${item.level.toUpperCase()}] ${item.message}${meta}`; | ||
} | ||
}]); | ||
return CloudWatchEventFormatter; | ||
}(); | ||
formatLogItem(item) { | ||
return { | ||
message: this.formatLog(item), | ||
timestamp: item.date | ||
}; | ||
} | ||
formatLog(item) { | ||
const meta = (0, _lodash2.default)(item.meta) ? '' : ' ' + (0, _stringify2.default)(item.meta, null, 2); | ||
return `[${item.level.toUpperCase()}] ${item.message}${meta}`; | ||
} | ||
} | ||
exports.default = CloudWatchEventFormatter; |
@@ -7,22 +7,2 @@ 'use strict'; | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _winston = require('winston'); | ||
@@ -44,28 +24,16 @@ | ||
var CloudWatchTransport = function (_Transport) { | ||
(0, _inherits3.default)(CloudWatchTransport, _Transport); | ||
class CloudWatchTransport extends _winston.Transport { | ||
constructor(options) { | ||
super(options); | ||
const client = new _cloudwatchClient2.default(options.logGroupName, options.logStreamName, options); | ||
this._relay = new _relay2.default(client, options); | ||
this._relay.on('error', err => this.emit('error', err)); | ||
this._relay.start(); | ||
} | ||
function CloudWatchTransport(options) { | ||
(0, _classCallCheck3.default)(this, CloudWatchTransport); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (CloudWatchTransport.__proto__ || (0, _getPrototypeOf2.default)(CloudWatchTransport)).call(this, options)); | ||
var client = new _cloudwatchClient2.default(options.logGroupName, options.logStreamName, options); | ||
_this._relay = new _relay2.default(client, options); | ||
_this._relay.on('error', function (err) { | ||
return _this.emit('error', err); | ||
}); | ||
_this._relay.start(); | ||
return _this; | ||
log(level, msg, meta, callback) { | ||
this._relay.submit(new _logItem2.default(+new Date(), level, msg, meta, callback)); | ||
} | ||
} | ||
(0, _createClass3.default)(CloudWatchTransport, [{ | ||
key: 'log', | ||
value: function log(level, msg, meta, callback) { | ||
this._relay.submit(new _logItem2.default(+new Date(), level, msg, meta, callback)); | ||
} | ||
}]); | ||
return CloudWatchTransport; | ||
}(_winston.Transport); | ||
exports.default = CloudWatchTransport; |
@@ -6,17 +6,4 @@ 'use strict'; | ||
}); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var LogItem = function () { | ||
function LogItem(date, level, message, meta, callback) { | ||
(0, _classCallCheck3.default)(this, LogItem); | ||
class LogItem { | ||
constructor(date, level, message, meta, callback) { | ||
this._date = date; | ||
@@ -29,31 +16,22 @@ this._level = level; | ||
(0, _createClass3.default)(LogItem, [{ | ||
key: 'date', | ||
get: function get() { | ||
return this._date; | ||
} | ||
}, { | ||
key: 'level', | ||
get: function get() { | ||
return this._level; | ||
} | ||
}, { | ||
key: 'message', | ||
get: function get() { | ||
return this._message; | ||
} | ||
}, { | ||
key: 'meta', | ||
get: function get() { | ||
return this._meta; | ||
} | ||
}, { | ||
key: 'callback', | ||
get: function get() { | ||
return this._callback; | ||
} | ||
}]); | ||
return LogItem; | ||
}(); | ||
get date() { | ||
return this._date; | ||
} | ||
get level() { | ||
return this._level; | ||
} | ||
get message() { | ||
return this._message; | ||
} | ||
get meta() { | ||
return this._meta; | ||
} | ||
get callback() { | ||
return this._callback; | ||
} | ||
} | ||
exports.default = LogItem; |
@@ -7,10 +7,2 @@ 'use strict'; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _debug2 = require('debug'); | ||
@@ -22,38 +14,28 @@ | ||
var debug = (0, _debug3.default)('winston-aws-cloudwatch:Queue'); | ||
const debug = (0, _debug3.default)('winston-aws-cloudwatch:Queue'); | ||
var Queue = function () { | ||
function Queue() { | ||
(0, _classCallCheck3.default)(this, Queue); | ||
class Queue { | ||
constructor() { | ||
this._contents = []; | ||
} | ||
(0, _createClass3.default)(Queue, [{ | ||
key: 'push', | ||
value: function push(item) { | ||
debug('push', { item }); | ||
this._contents.push(item); | ||
} | ||
}, { | ||
key: 'head', | ||
value: function head(num) { | ||
debug('head', { num }); | ||
return this._contents.slice(0, num); | ||
} | ||
}, { | ||
key: 'remove', | ||
value: function remove(num) { | ||
debug('remove', { num }); | ||
this._contents.splice(0, num); | ||
} | ||
}, { | ||
key: 'size', | ||
get: function get() { | ||
return this._contents.length; | ||
} | ||
}]); | ||
return Queue; | ||
}(); | ||
get size() { | ||
return this._contents.length; | ||
} | ||
push(item) { | ||
debug('push', { item }); | ||
this._contents.push(item); | ||
} | ||
head(num) { | ||
debug('head', { num }); | ||
return this._contents.slice(0, num); | ||
} | ||
remove(num) { | ||
debug('remove', { num }); | ||
this._contents.splice(0, num); | ||
} | ||
} | ||
exports.default = Queue; |
170
lib/relay.js
@@ -11,22 +11,6 @@ 'use strict'; | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _debug2 = require('debug'); | ||
@@ -40,6 +24,2 @@ | ||
var _defaults = require('defaults'); | ||
var _defaults2 = _interopRequireDefault(_defaults); | ||
var _queue = require('./queue'); | ||
@@ -53,103 +33,71 @@ | ||
var debug = (0, _debug3.default)('winston-aws-cloudwatch:Relay'); | ||
const debug = (0, _debug3.default)('winston-aws-cloudwatch:Relay'); | ||
var Relay = function (_EventEmitter) { | ||
(0, _inherits3.default)(Relay, _EventEmitter); | ||
const DEFAULT_OPTIONS = { | ||
submissionInterval: 2000, | ||
batchSize: 20 | ||
}; | ||
function Relay(client, options) { | ||
(0, _classCallCheck3.default)(this, Relay); | ||
class Relay extends _events.EventEmitter { | ||
constructor(client, options) { | ||
super(); | ||
debug('constructor', { client, options }); | ||
this._client = client; | ||
this._options = (0, _assign2.default)({}, DEFAULT_OPTIONS, options); | ||
this._limiter = null; | ||
this._queue = null; | ||
} | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Relay.__proto__ || (0, _getPrototypeOf2.default)(Relay)).call(this)); | ||
start() { | ||
debug('start'); | ||
if (this._queue) { | ||
throw new Error('Already started'); | ||
} | ||
this._limiter = new _bottleneck2.default(1, this._options.submissionInterval, 1); | ||
this._queue = new _queue2.default(); | ||
// Initial call to postpone first submission | ||
this._limiter.schedule(() => _promise2.default.resolve()); | ||
} | ||
debug('constructor', { client, options }); | ||
_this._client = client; | ||
_this._options = (0, _defaults2.default)(options, { | ||
submissionInterval: 2000, | ||
batchSize: 20 | ||
}); | ||
_this._limiter = null; | ||
_this._queue = null; | ||
return _this; | ||
submit(item) { | ||
this._queue.push(item); | ||
this._scheduleSubmission(); | ||
} | ||
(0, _createClass3.default)(Relay, [{ | ||
key: 'start', | ||
value: function start() { | ||
debug('start'); | ||
if (this._queue) { | ||
throw new Error('Already started'); | ||
} | ||
this._limiter = new _bottleneck2.default(1, this._options.submissionInterval, 1); | ||
this._queue = new _queue2.default(); | ||
// Initial call to postpone first submission | ||
this._limiter.schedule(function () { | ||
return _promise2.default.resolve(); | ||
}); | ||
_scheduleSubmission() { | ||
debug('scheduleSubmission'); | ||
this._limiter.schedule(() => this._submit()); | ||
} | ||
_submit() { | ||
if (this._queue.size === 0) { | ||
debug('submit: queue empty'); | ||
return _promise2.default.resolve(); | ||
} | ||
}, { | ||
key: 'submit', | ||
value: function submit(item) { | ||
this._queue.push(item); | ||
this._scheduleSubmission(); | ||
} | ||
}, { | ||
key: '_scheduleSubmission', | ||
value: function _scheduleSubmission() { | ||
var _this2 = this; | ||
const batch = this._queue.head(this._options.batchSize); | ||
debug(`submit: submitting ${batch.length} item(s)`); | ||
return this._client.submit(batch).then(() => this._onSubmitted(batch), err => this._onError(err, batch)).then(() => this._scheduleSubmission()); | ||
} | ||
debug('scheduleSubmission'); | ||
this._limiter.schedule(function () { | ||
return _this2._submit(); | ||
}); | ||
_onSubmitted(batch) { | ||
debug('onSubmitted', { batch }); | ||
this._queue.remove(batch.length); | ||
for (let i = 0; i < batch.length; ++i) { | ||
const item = batch[i]; | ||
item.callback(null, true); | ||
} | ||
}, { | ||
key: '_submit', | ||
value: function _submit() { | ||
var _this3 = this; | ||
} | ||
if (this._queue.size === 0) { | ||
debug('submit: queue empty'); | ||
return _promise2.default.resolve(); | ||
} | ||
var batch = this._queue.head(this._options.batchSize); | ||
debug(`submit: submitting ${batch.length} item(s)`); | ||
return this._client.submit(batch).then(function () { | ||
return _this3._onSubmitted(batch); | ||
}, function (err) { | ||
return _this3._onError(err, batch); | ||
}).then(function () { | ||
return _this3._scheduleSubmission(); | ||
}); | ||
} | ||
}, { | ||
key: '_onSubmitted', | ||
value: function _onSubmitted(batch) { | ||
debug('onSubmitted', { batch }); | ||
_onError(err, batch) { | ||
debug('onError', { error: err }); | ||
if (err.code === 'DataAlreadyAcceptedException') { | ||
// Assume the request got replayed and remove the batch | ||
this._queue.remove(batch.length); | ||
for (var i = 0; i < batch.length; ++i) { | ||
var item = batch[i]; | ||
item.callback(null, true); | ||
} | ||
} else if (err.code === 'InvalidSequenceTokenException') { | ||
// Keep retrying | ||
} else { | ||
this.emit('error', err); | ||
} | ||
}, { | ||
key: '_onError', | ||
value: function _onError(err, batch) { | ||
debug('onError', { error: err }); | ||
// Expected errors: | ||
// - DataAlreadyAcceptedException | ||
// Message: "The given batch of log events has already been accepted." | ||
// Action: Assume the request got replayed and remove the batch. | ||
// - InvalidSequenceTokenException | ||
// Message: "The given sequenceToken is invalid." | ||
// Action: Keep the items in the queue and retry next time. | ||
if (err.code === 'DataAlreadyAcceptedException') { | ||
this._queue.remove(batch.length); | ||
} else if (err.code !== 'InvalidSequenceTokenException') { | ||
this.emit('error', err); | ||
} | ||
} | ||
}]); | ||
return Relay; | ||
}(_events.EventEmitter); | ||
} | ||
} | ||
exports.default = Relay; |
{ | ||
"name": "winston-aws-cloudwatch", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "A Winston transport for Amazon CloudWatch.", | ||
@@ -18,4 +18,8 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6", | ||
"yarn": "*" | ||
}, | ||
"peerDependencies": { | ||
"winston": "^2.3.1" | ||
}, | ||
"dependencies": { | ||
@@ -25,23 +29,19 @@ "aws-sdk": "^2.58.0", | ||
"bottleneck": "^1.15.1", | ||
"debug": "^2.6.8", | ||
"defaults": "^1.0.3", | ||
"lodash.find": "^4.4.0", | ||
"lodash.isempty": "^4.2.1", | ||
"winston": "^2.3.1" | ||
"debug": "^3.1.0", | ||
"lodash.isempty": "^4.2.1" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.26.0", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-preset-env": "^1.5.1", | ||
"babel-register": "^6.24.1", | ||
"chai": "^4.0.2", | ||
"chai-as-promised": "^7.0.0", | ||
"coveralls": "^2.13.1", | ||
"coveralls": "^3.0.0", | ||
"delay": "^2.0.0", | ||
"in-publish": "^2.0.0", | ||
"mocha": "^3.4.2", | ||
"mocha": "^4.0.1", | ||
"mocha-junit-reporter": "^1.13.0", | ||
"nyc": "^11.0.3", | ||
"rimraf": "^2.6.1", | ||
"sinon": "^2.3.1", | ||
"sinon": "^4.1.2", | ||
"sinon-chai": "^2.10.0", | ||
@@ -56,11 +56,12 @@ "standard": "^10.0.2" | ||
"scripts": { | ||
"prepublish": "in-publish && npm run build || not-in-publish", | ||
"prepublishOnly": "yarn run build", | ||
"clean": "rimraf lib", | ||
"build": "npm run clean && babel src --out-dir lib", | ||
"test": "npm run test:lint && npm run test:cover", | ||
"build": "yarn run clean && babel src --out-dir lib", | ||
"test": "yarn run test:lint && yarn run test:cover", | ||
"test:lint": "standard", | ||
"test:unit": "mocha --compilers js:babel-register test/lib/setup.js test/**/*.spec.js", | ||
"test:cover": "nyc npm run test:unit", | ||
"test:ci": "npm run test:ci:cover && npm run test:ci:report", | ||
"test:ci:cover": "nyc mocha --reporter mocha-junit-reporter --compilers js:babel-register test/lib/setup.js test/**/*.spec.js", | ||
"test:unit": "mocha --require babel-core/register test/lib/setup.js test/**/*.spec.js", | ||
"test:cover": "nyc yarn run test:unit", | ||
"test:ci": "yarn run test:ci:cover && yarn run test:ci:report", | ||
"test:ci:unit": "mocha --reporter mocha-junit-reporter --require babel-core/register test/lib/setup.js test/**/*.spec.js", | ||
"test:ci:cover": "nyc yarn run test:ci:unit", | ||
"test:ci:report": "nyc report --reporter text-lcov | coveralls", | ||
@@ -67,0 +68,0 @@ "dev": "babel src --out-dir lib --watch" |
# winston-aws-cloudwatch | ||
[![npm](https://img.shields.io/npm/v/winston-aws-cloudwatch.svg)](https://www.npmjs.com/package/winston-aws-cloudwatch) [![Dependencies](https://img.shields.io/david/timdp/winston-aws-cloudwatch.svg)](https://david-dm.org/timdp/winston-aws-cloudwatch) [![CircleCI Build Status](https://img.shields.io/circleci/project/github/timdp/winston-aws-cloudwatch/master.svg?label=circleci+build)](https://circleci.com/gh/timdp/winston-aws-cloudwatch) [![AppVeyor Build Status](https://img.shields.io/appveyor/ci/timdp/winston-aws-cloudwatch/master.svg?label=appveyor+build)](https://ci.appveyor.com/project/timdp/winston-aws-cloudwatch) [![Coverage Status](https://img.shields.io/coveralls/timdp/winston-aws-cloudwatch/master.svg)](https://coveralls.io/r/timdp/winston-aws-cloudwatch) [![JavaScript Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
[![npm](https://img.shields.io/npm/v/winston-aws-cloudwatch.svg)](https://www.npmjs.com/package/winston-aws-cloudwatch) [![Dependencies](https://img.shields.io/david/timdp/winston-aws-cloudwatch.svg)](https://david-dm.org/timdp/winston-aws-cloudwatch) [![Build Status](https://img.shields.io/circleci/project/github/timdp/winston-aws-cloudwatch/master.svg?label=build)](https://circleci.com/gh/timdp/winston-aws-cloudwatch) [![Coverage Status](https://img.shields.io/coveralls/timdp/winston-aws-cloudwatch/master.svg)](https://coveralls.io/r/timdp/winston-aws-cloudwatch) [![JavaScript Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
@@ -19,2 +19,3 @@ A [Winston](https://www.npmjs.com/package/winston) transport for | ||
submissionInterval: 2000, | ||
submissionRetryCount: 1, | ||
batchSize: 20, | ||
@@ -21,0 +22,0 @@ awsConfig: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6
15
53
16215
313
1
+ Addeddebug@3.2.7(transitive)
+ Addedms@2.1.3(transitive)
- Removeddefaults@^1.0.3
- Removedlodash.find@^4.4.0
- Removedwinston@^2.3.1
- Removedclone@1.0.4(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddefaults@1.0.4(transitive)
- Removedlodash.find@4.6.0(transitive)
- Removedms@2.0.0(transitive)
Updateddebug@^3.1.0