winston-cloudwatch
Advanced tools
Comparing version 2.3.1 to 2.3.2
@@ -0,1 +1,5 @@ | ||
### 2.3.2 | ||
kthxbye will try to flush events before stopping the interval | ||
### 2.3.1 | ||
@@ -2,0 +6,0 @@ |
15
index.js
@@ -11,5 +11,5 @@ 'use strict'; | ||
stringify = require('./lib/utils').stringify, | ||
debug = require('./lib/utils').debug; | ||
debug = require('./lib/utils').debug, | ||
defaultFlushTimeoutMs = 10000; | ||
var WinstonCloudWatch = function(options) { | ||
@@ -136,6 +136,13 @@ winston.Transport.call(this, options); | ||
WinstonCloudWatch.prototype.kthxbye = function(callback) { | ||
WinstonCloudWatch.prototype.kthxbye = function(callback) { | ||
clearInterval(this.intervalId); | ||
this.intervalId = null; | ||
this.submit(callback); | ||
this.flushTimeout = this.flushTimeout || (Date.now() + defaultFlushTimeoutMs); | ||
this.submit((function(error) { | ||
if (error) return callback(error); | ||
if (isEmpty(this.logEvents)) return callback(); | ||
if (Date.now() > this.flushTimeout) return callback(new Error('Timeout reached while waiting for logs to submit')); | ||
else setTimeout(this.kthxbye.bind(this, callback), 0); | ||
}).bind(this)); | ||
}; | ||
@@ -142,0 +149,0 @@ |
{ | ||
"name": "winston-cloudwatch", | ||
"version": "2.3.1", | ||
"version": "2.3.2", | ||
"description": "Send logs to Amazon Cloudwatch using Winston.", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"aws-sdk": "^2.553.0", | ||
"chalk": "^2.4.2", | ||
"chalk": "^4.0.0", | ||
"fast-safe-stringify": "^2.0.7", | ||
@@ -38,3 +38,3 @@ "lodash.assign": "^4.2.0", | ||
"devDependencies": { | ||
"@types/node": "12.11.2", | ||
"@types/node": "13.11.0", | ||
"@types/winston": "2.4.4", | ||
@@ -44,8 +44,8 @@ "clarify": "^2.1.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^6.2.2", | ||
"mocha": "^7.1.1", | ||
"mockery": "^2.1.0", | ||
"npm-check-updates": "^3.1.25", | ||
"npm-check-updates": "^4.1.1", | ||
"should": "^13.2.3", | ||
"sinon": "^7.5.0" | ||
"sinon": "^9.0.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# winston-cloudwatch [v2.3.1](https://github.com/lazywithclass/winston-cloudwatch/blob/master/CHANGELOG.md#231) | ||
# winston-cloudwatch [v2.3.2](https://github.com/lazywithclass/winston-cloudwatch/blob/master/CHANGELOG.md#232) | ||
@@ -3,0 +3,0 @@ [![Build Status](https://travis-ci.org/lazywithclass/winston-cloudwatch.svg?branch=master)](https://travis-ci.org/lazywithclass/winston-cloudwatch) [![Coverage Status](https://coveralls.io/repos/github/lazywithclass/winston-cloudwatch/badge.svg?branch=master)](https://coveralls.io/github/lazywithclass/winston-cloudwatch?branch=master) [![Dependency Status](https://david-dm.org/lazywithclass/winston-cloudwatch.svg)](https://david-dm.org/lazywithclass/winston-cloudwatch) [![dev dependencies](https://david-dm.org/lazywithclass/winston-cloudwatch/dev-status.svg)](https://david-dm.org/lazywithclass/winston-cloudwatch#info=devDependencies) [![peer dependencies](https://david-dm.org/lazywithclass/winston-cloudwatch/peer-status.svg)](https://david-dm.org/lazywithclass/winston-cloudwatch#info=peerDependencies) |
@@ -52,2 +52,3 @@ describe('index', function() { | ||
mockery.disable(); | ||
clock.restore(); | ||
}); | ||
@@ -216,5 +217,3 @@ | ||
afterEach(function() { | ||
stubbedCloudwatchIntegration = { | ||
upload: sinon.spy() | ||
}; | ||
stubbedCloudwatchIntegration.upload = sinon.spy(); | ||
console.error.restore(); | ||
@@ -251,3 +250,6 @@ }); | ||
transport = new WinstonCloudWatch({}); | ||
sinon.stub(transport, 'submit').yields(); | ||
sinon.stub(transport, 'submit').callsFake(function(cb){ | ||
this.logEvents.splice(0, 20); | ||
cb(); | ||
}); | ||
}); | ||
@@ -277,4 +279,33 @@ | ||
}); | ||
it('should not send all messages if called while posting', function(done) { | ||
for (var index = 0; index < 30; index++) { | ||
transport.add({ message: 'message' + index }); | ||
} | ||
transport.kthxbye(function() { | ||
transport.logEvents.length.should.equal(0); | ||
done(); | ||
}); | ||
clock.tick(1); | ||
}); | ||
it('should exit if logs are not cleared by the timeout period', function(done) { | ||
transport.add({ message: 'message' }); | ||
transport.submit.callsFake(function(cb){ | ||
clock.tick(500); | ||
cb(); // callback is called but logEvents is not cleared | ||
}); | ||
transport.kthxbye(function(error) { | ||
error.should.be.Error(); | ||
transport.logEvents.length.should.equal(1); | ||
done(); | ||
}); | ||
clock.tick(1); | ||
}); | ||
}); | ||
}); |
60291
25
1274
+ Addedansi-styles@4.3.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedchalk@^4.0.0