Socket
Socket
Sign inDemoInstall

pino-socket

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pino-socket - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

lib/TcpConnection.js

6

changelog.md

@@ -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 @@

pino-socket

@@ -13,10 +13,12 @@

Flags
-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
-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"
}
}
'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.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc