@madgex/datadog-logger
Advanced tools
Comparing version 1.1.2 to 1.1.3
{ | ||
"name": "@madgex/datadog-logger", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Setup console and Hapi Good logger", | ||
@@ -5,0 +5,0 @@ "main": "logger_setup.js", |
@@ -1,5 +0,5 @@ | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
const winston = require('winston'); | ||
const { MESSAGE } = require('triple-beam'); | ||
const assert = require("assert"); | ||
const dgram = require("dgram"); | ||
const winston = require("winston"); | ||
const { MESSAGE } = require("triple-beam"); | ||
@@ -10,7 +10,4 @@ module.exports = class Transport extends winston.Transport { | ||
{ | ||
level: 'info', | ||
enableInternalDebugging: false, | ||
reconnectInterval: 1000, | ||
reconnectAttempts: 100, | ||
bufferLength: 10000, | ||
level: "info", | ||
enableInternalDebugging: false | ||
}, | ||
@@ -25,10 +22,8 @@ options | ||
assert(this.options.host, 'Must define a host'); | ||
assert(this.options.port, 'Must supply a port'); | ||
assert(this.options.host, "Must define a host"); | ||
assert(this.options.port, "Must supply a port"); | ||
// generic transport requirements | ||
this.name = 'winston-udp'; | ||
this.name = "winston-udp"; | ||
// initiate entry buffer | ||
this.entryBuffer = []; | ||
this.udpClient = null; | ||
@@ -44,8 +39,2 @@ | ||
pushMessage(message) { | ||
if (this.entryBuffer.length < this.options.bufferLength) { | ||
this.entryBuffer.push(message); | ||
} | ||
} | ||
getLevelNo(level) { | ||
@@ -61,25 +50,27 @@ var levelDef = this.levels[level]; | ||
const logEntry = `${entry[MESSAGE]}\n`; | ||
this.pushMessage(new Buffer(logEntry)); | ||
const message = new Buffer(logEntry); | ||
if(!this.udpClient) { | ||
this.udpClient = dgram.createSocket('udp4'); | ||
if (!this.udpClient) { | ||
this.udpClient = dgram.createSocket("udp4"); | ||
} | ||
while (this.udpClient && this.entryBuffer.length) { | ||
const message = this.entryBuffer.pop(); | ||
if (message) { | ||
this.udpClient.send(message, 0, message.length, this.options.port, this.options.host, function(err, bytes) { | ||
if (err) { | ||
this.close(); | ||
this.internalDebug('writing to buffer', err); | ||
this.entryBuffer.push(bytes); | ||
} | ||
}); | ||
this.udpClient.send( | ||
message, | ||
0, | ||
message.length, | ||
this.options.port, | ||
this.options.host, | ||
function(err, bytes) { | ||
if (err) { | ||
this.close(); | ||
console.log("udp logging failed - log to console"); | ||
console.log(logEntry); | ||
} | ||
} | ||
); | ||
if (typeof callback === "function") { | ||
callback(null, true); | ||
} | ||
} | ||
if (typeof callback === 'function') { | ||
callback(null, true); | ||
} | ||
} | ||
@@ -92,3 +83,3 @@ | ||
close() { | ||
if(this.udpClient) { | ||
if (this.udpClient) { | ||
this.udpClient.close(); | ||
@@ -95,0 +86,0 @@ this.udpClient = null; |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
20977
514