log4js-logstash-tcp
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -6,9 +6,12 @@ "use strict"; | ||
const MAX_TCP_CONNECITONS = 300; | ||
const DEFAULT_MAX_TCP_CONNECTIONS = 300; | ||
class TcpConnectionWrapper extends EventEmitter { | ||
constructor(host, port) { | ||
constructor(host, port, config) { | ||
super(); | ||
this.connectionNotReadyRetryInterval = parseInt(config.connectionNotReadyRetryInterval || 500); | ||
this.connectionTimeout = parseInt(config.connectionTimeout || 5000); | ||
const self = this; | ||
@@ -22,7 +25,7 @@ this.connection = net.connect({ | ||
this.connection.setTimeout(5000); | ||
this.connection.setTimeout(this.connectionTimeout); | ||
this.connection.on("timeout", () => {self.destroy()}); | ||
this.connection.on("close", () => {self.destroy()}); | ||
this.connection.on("error", (err) => { | ||
console.error(`Error with the connection to ${host}:${port}. ${err}`); | ||
console.error(`logstash Error with the connection to ${host}:${port}. ${err}`); | ||
// From docs: "The close event will be called just after this one | ||
@@ -41,5 +44,14 @@ }); | ||
this.connection.write(message) | ||
this.realSend(message); | ||
} | ||
realSend(message) { | ||
const self = this; | ||
if(this.connected === true) { | ||
this.connection.write(message) | ||
} else { | ||
setTimeout(() => {self.realSend(message);}, this.connectionNotReadyRetryInterval); | ||
} | ||
} | ||
destroy() { | ||
@@ -56,5 +68,11 @@ this.connection.end(); | ||
constructor() { | ||
constructor(config) { | ||
this.tcpConnections = {} | ||
if(config) this.config = config; | ||
else this.config = {}; | ||
if(!this.config.maxTcpConnections) { | ||
this.config.maxTcpConnections = DEFAULT_MAX_TCP_CONNECTIONS; | ||
} | ||
} | ||
@@ -67,3 +85,3 @@ | ||
_getTcpConnection(host, port) { | ||
const index = TcpConnectionPool._createIndexForTcpConnection(); | ||
const index = this._createIndexForTcpConnection(); | ||
return this.tcpConnections[index] || this._createTcpConnection(index, host, port); | ||
@@ -74,3 +92,3 @@ } | ||
const self = this; | ||
const tcpConnectionWrapper = new TcpConnectionWrapper(host, port); | ||
const tcpConnectionWrapper = new TcpConnectionWrapper(host, port, this.config); | ||
this.tcpConnections[index] = tcpConnectionWrapper; | ||
@@ -85,4 +103,4 @@ | ||
static _createIndexForTcpConnection() { | ||
return Math.floor( Math.random() * MAX_TCP_CONNECITONS) % MAX_TCP_CONNECITONS; | ||
_createIndexForTcpConnection() { | ||
return Math.floor( Math.random() * this.config.maxTcpConnections) % this.config.maxTcpConnections; | ||
} | ||
@@ -89,0 +107,0 @@ |
{ | ||
"name": "log4js-logstash-tcp", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"author": "Aigent B.V.", | ||
@@ -5,0 +5,0 @@ "description": "This is a copy of the logstashUDP appender but instead sending via UDP send via TCP to avoid the maximum 64k bytes message size with the logstashUDP appender.", |
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
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
31965
211
9