pino-socket
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,7 @@ | ||
### 0.4.0 | ||
+ Add support for reconnecting to dropped TCP destinations (issue #3) | ||
+ `--reconnect` (`-r`) to enable | ||
+ `--reconnectTries <n>` (`-t <n>`) to set the number of retries | ||
before giving up (default: infinite) | ||
### 0.3.0 | ||
@@ -2,0 +8,0 @@ + Add cli help output via `--help` (@mcollina) |
20
help.txt
@@ -1,2 +0,2 @@ | ||
[0m[37m[1m[4mpino-socket[22m[39m[0m | ||
@@ -13,10 +13,12 @@ | ||
[36m[1mFlags[22m[39m | ||
[0m-h | --help Display Help | ||
-v | --version display Version | ||
-a | --address the address for the destination socket; default: 127.0.0.1 | ||
-m | --mode the protocol, either 'udp' or 'tcp'; default: 'udp' | ||
-p | --port the port on the destination socket; default: '514' | ||
-ne | --no-echo disable echoing received messages to stdout | ||
-c | --cee prefix the message with '@cee: '; default: disabled | ||
-nc | --no-cee disable cee explicitly | ||
[0m-h | --help Display Help | ||
-v | --version display Version | ||
-a | --address the address for the destination socket; default: 127.0.0.1 | ||
-m | --mode the protocol, either 'udp' or 'tcp'; default: 'udp' | ||
-p | --port the port on the destination socket; default: '514' | ||
-r | --reconnect enable tcp mode reconnecting | ||
-t | --reconnectTries number of reconnect attempts to make; default 'Inifinity' | ||
-ne | --no-echo disable echoing received messages to stdout | ||
-c | --cee prefix the message with '@cee: '; default: disabled | ||
-nc | --no-cee disable cee explicitly | ||
{ | ||
"name": "pino-socket", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A pino 'transport' for writing to a tcp or udp socket", | ||
@@ -41,7 +41,10 @@ "homepage": "https://github.com/jsumners/pino-socket", | ||
"dependencies": { | ||
"backoff": "^2.5.0", | ||
"nopt": "^3.0.6", | ||
"pump": "^1.0.1", | ||
"safe-buffer": "^5.0.1", | ||
"split2": "^2.0.1", | ||
"tcp-ping": "^0.1.1", | ||
"through2": "^2.0.1" | ||
} | ||
} |
65
psock.js
'use strict' | ||
const net = require('net') | ||
const dgram = require('dgram') | ||
const path = require('path') | ||
const tcpConnectionFactory = require(path.join(__dirname, 'lib', 'TcpConnection')) | ||
const udpConnectionFactory = require(path.join(__dirname, 'lib', 'UdpConnection')) | ||
const split2 = require('split2') | ||
@@ -10,3 +11,2 @@ const pump = require('pump') | ||
const fs = require('fs') | ||
const path = require('path') | ||
@@ -18,3 +18,5 @@ let options = { | ||
echo: true, | ||
cee: false | ||
cee: false, | ||
reconnect: false, | ||
reconnectTries: Infinity | ||
} | ||
@@ -25,2 +27,4 @@ const longOpts = { | ||
port: Number, | ||
reconnect: Boolean, | ||
reconnectTries: Number, | ||
echo: Boolean, | ||
@@ -35,2 +39,4 @@ cee: Boolean, | ||
p: '--port', | ||
r: '--reconnect', | ||
t: '--reconnectTries', | ||
e: '--echo', | ||
@@ -58,48 +64,7 @@ ne: '--no-echo', | ||
function TcpWriter (socket) { | ||
if (options.cee) { | ||
Object.defineProperty(this, 'write', { | ||
value: (message) => socket.write(`@cee: ${message}\n`) | ||
}) | ||
} else { | ||
Object.defineProperty(this, 'write', { | ||
value: (message) => socket.write(`${message}\n`) | ||
}) | ||
} | ||
} | ||
function UdpWriter (socket) { | ||
if (options.cee) { | ||
Object.defineProperty(this, 'write', { | ||
value: (message) => { | ||
const buf = new Buffer(`@cee: ${message}\n`, 'utf8') | ||
socket.send(buf, 0, buf.length, options.port, options.address) | ||
} | ||
}) | ||
} else { | ||
Object.defineProperty(this, 'write', { | ||
value: (message) => { | ||
const buf = new Buffer(`${message}\n`, 'utf8') | ||
socket.send(buf, 0, buf.length, options.port, options.address) | ||
} | ||
}) | ||
} | ||
} | ||
let socket | ||
let send | ||
let close | ||
let connection | ||
if (options.mode === 'tcp') { | ||
socket = net.createConnection({ | ||
host: options.address, | ||
port: options.port | ||
}) | ||
const writer = new TcpWriter(socket) | ||
send = writer.write | ||
close = socket.end | ||
connection = tcpConnectionFactory(options) | ||
} else { | ||
socket = dgram.createSocket('udp4') | ||
const writer = new UdpWriter(socket) | ||
send = writer.write | ||
close = socket.close | ||
connection = udpConnectionFactory(options) | ||
} | ||
@@ -117,3 +82,3 @@ | ||
try { | ||
close() | ||
connection.close() | ||
} catch (e) { | ||
@@ -136,3 +101,3 @@ // I assume that due to the closing of the pipe, the dgram/tcp socket has | ||
setImmediate(log.bind(null, chunk)) | ||
setImmediate(() => send(chunk)) | ||
setImmediate(() => connection.write(chunk)) | ||
cb() | ||
@@ -139,0 +104,0 @@ }) |
@@ -30,2 +30,5 @@ # pino-socket | ||
+ `--port` (`-p`): the port for the destination socket. Default: `514`. | ||
+ `--reconnect` (`-r`): enable reconnecting to dropped TCP destinations. Default: off | ||
+ `--reconnectTries <n>` (`-t <n>`): set number (`<n>`) of reconnect attempts | ||
before giving up. Default: infinite | ||
+ `--echo` (`-e`): echo the received messages to stdout. Default: enabled. | ||
@@ -32,0 +35,0 @@ + `--no-echo` (`-ne`): disable echoing received messages to stdout. |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
21259
16
512
44
7
5
8
+ Addedbackoff@^2.5.0
+ Addedsafe-buffer@^5.0.1
+ Addedtcp-ping@^0.1.1
+ Addedbackoff@2.5.0(transitive)
+ Addedprecond@0.2.3(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedtcp-ping@0.1.1(transitive)