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.
npm install logstash-clientVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your Logstash TCP input codec is configured to handle newline-delimited JSON (e.g., `json_lines {}`). If you have a custom `format` function, remove any manually added newlines to avoid double newlines, or adjust your Logstash configuration accordingly.It is highly recommended to migrate to a modern, actively maintained Logstash client or a general-purpose logging library with Logstash transport support (e.g., Winston, Pino, Bunyan with their respective Logstash transports) for better compatibility, performance, and security.
For larger messages, use the TCP transport, which handles message streaming more robustly. If UDP must be used, ensure messages are kept small and consider implementing application-level message chunking and reassembly if necessary.
Always provide a callback function to the `send` method to handle potential errors and ensure message delivery status is monitored. Implement retry mechanisms or dead-letter queues at the application level for critical logs.
This package is CommonJS-only. Convert your project to CommonJS, or use a modern Logstash client that supports ES modules. If you must use this package in an ESM context, consider a wrapper function or a build step like Webpack/Rollup that can handle CJS modules.
Verify that your Logstash instance is running and has an input configured for the specified type (UDP/TCP) on the correct host and port. Check firewall rules between your Node.js application and the Logstash server.
Ensure you are using `logstash-client` version 1.0.2 or newer. If you provide a custom `format` function, ensure it appends a newline character (`\n`) after stringifying your JSON message (e.g., `return JSON.stringify(message) + '\n';`). Confirm your Logstash input configuration uses `codec => json_lines {}`.