Skip to content

Commit

Permalink
Merge pull request #42 from djMax/mm_modernize
Browse files Browse the repository at this point in the history
Cleanup async handling in tests, fix auto-reconnect after a close, de…
  • Loading branch information
djMax authored Oct 24, 2016
2 parents aa378b4 + e434a54 commit 0626043
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
sudo: false
language: node_js
node_js:
- "6"
- "5"
- "4"
- "0.12"
- "0.11"
- "0.10"
- "0.8"
- "iojs"
env: NODE_TLS_REJECT_UNAUTHORIZED=0
9 changes: 8 additions & 1 deletion lib/winston-logstash.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ Logstash.prototype.connect = function () {
this.socket.on('close', function (had_error) {
self.connected = false;

if (self.terminating) {
return;
}

if (self.max_connect_retries < 0 || self.retries < self.max_connect_retries) {
if (!self.connecting) {
setTimeout(function () {
Expand Down Expand Up @@ -232,7 +236,6 @@ Logstash.prototype.flush = function () {

for (var i = 0; i < self.log_queue.length; i++) {
self.sendLog(self.log_queue[i].message, self.log_queue[i].callback);
self.emit('logged');
}
self.log_queue.length = 0;
};
Expand All @@ -244,3 +247,7 @@ Logstash.prototype.sendLog = function (message, callback) {
self.socket.write(message + '\n');
callback();
};

Logstash.prototype.getQueueLength = function () {
return this.log_queue.length;
};
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "winston-logstash",
"version": "0.2.11",
"version": "0.3.0",
"description": "A Logstash transport for winston",
"main": "./lib/winston-logstash",
"homepage": "https://github.com/jaakkos/winston-logstash",
Expand All @@ -18,10 +18,10 @@
"winston": ">=0.7.3"
},
"devDependencies": {
"winston": ">=0.7.3",
"mocha": ">=2.2.4",
"chai": ">=2.3.0",
"timekeeper": ">=0.0.5"
"mocha": ">=2.2.4",
"timekeeper": ">=0.0.5",
"winston": ">=0.7.3"
},
"keywords": [
"logging",
Expand All @@ -36,6 +36,7 @@
"contributors": [
"Jaakko Suutarla <jaakko@suutarla.com>",
"Chris Saylor <cjsaylor@gmail.com>",
"djmax",
"gwhitelaw",
"Ivan Fraixedes",
"kgoerlitz",
Expand Down
26 changes: 15 additions & 11 deletions test/winston-logstash_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('winston-logstash transport', function() {
}

function createTestServer(port, on_data) {
var server = net.createServer(port, function (socket) {
var server = net.createServer(function (socket) {
socket.on('end', function () { });
socket.on('data', on_data);
});
Expand Down Expand Up @@ -143,16 +143,18 @@ describe('winston-logstash transport', function() {
});

// Teardown
afterEach(function () {
afterEach(function (done) {
if (logger) {
logger.close();
}
timekeeper.reset();
if (test_server) {
test_server.close(function () {});
test_server.close(function () {
test_server = null;
logger = null;
done();
});
}
timekeeper.reset();
test_server = null;
logger = null;
});

});
Expand Down Expand Up @@ -225,16 +227,18 @@ describe('winston-logstash transport', function() {
});

// Teardown
afterEach(function () {
afterEach(function (done) {
if (logger) {
logger.close();
}
timekeeper.reset();
if (test_server) {
test_server.close(function () {});
test_server.close(function () {
test_server = null;
logger = null;
done();
});
}
timekeeper.reset();
test_server = null;
logger = null;
});
});

Expand Down

0 comments on commit 0626043

Please sign in to comment.