Logstash Client

1.1.1 · abandoned · verified Tue Apr 21

logstash-client is a general-purpose Node.js library for sending logs to Logstash instances. It provides support for UDP, TCP, and in-memory transports, designed to be independent of specific logging frameworks like Winston or Bunyan. The package's current stable version is 1.1.1, which was published in 2016. Due to its age and lack of updates, the release cadence is inactive, and the library is no longer under active development. Key differentiators at the time of its development included its transport flexibility and independence from specific logger implementations, allowing it to integrate with various Node.js applications. However, this also means it predates modern JavaScript features and best practices.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates setting up both UDP and TCP clients for logstash-client, sending a simple message with and without a custom formatter, and handling potential errors.

const Logstash = require('logstash-client');

// Configure a UDP client to send messages to Logstash
const logstashUdp = new Logstash({
  type: 'udp',
  host: 'localhost', // Replace with your Logstash host
  port: 13333 // Replace with your Logstash UDP input port
});

// Send a basic log message
logstashUdp.send({
  '@timestamp': new Date().toISOString(),
  'message': 'Hello from logstash-client UDP!',
  'level': 'info',
  'service': 'my-node-app'
}, (err) => {
  if (err) {
    console.error('Error sending UDP message:', err);
  } else {
    console.log('UDP message sent successfully.');
  }
});

// Configure a TCP client (requires a Logstash TCP input, e.g., on port 8099)
const logstashTcp = new Logstash({
  type: 'tcp',
  host: 'localhost', // Replace with your Logstash host
  port: 8099, // Replace with your Logstash TCP input port
  format: (message) => {
    // Custom formatter: add a timestamp and filter sensitive data
    message.formattedAt = new Date().toISOString();
    message.apiKey = '[FILTERED]';
    return JSON.stringify(message) + '\n'; // Ensure newline for TCP streams
  }
});

logstashTcp.send({
  'event': 'user_login',
  'userId': 123,
  'apiKey': process.env.API_KEY ?? 'secret_key_if_not_set',
  'status': 'success'
}, (err) => {
  if (err) {
    console.error('Error sending TCP message:', err);
  } else {
    console.log('TCP message sent successfully.');
  }
});

view raw JSON →