{"id":15849,"library":"syslog-client","title":"Syslog Client for Node.js","description":"`syslog-client` is a pure JavaScript library for Node.js, designed to send log messages to remote syslog servers. It supports both the legacy BSD Syslog Protocol (RFC 3164) and the modern Syslog Protocol (RFC 5424), offering flexibility in message formatting. The library facilitates communication over both TCP and UDP transports, providing options to configure the target host, port, facility, and severity for outgoing messages. Currently at version 1.1.1, with its last update approximately 9 years ago, the package is considered to be in maintenance status. Its key differentiators include comprehensive RFC support and a simple API for common syslog operations, though developers should be aware of its age and lack of recent updates when considering new projects.","status":"maintenance","version":"1.1.1","language":"javascript","source_language":"en","source_url":"git://github.com/paulgrove/node-syslog-client","tags":["javascript","logger","logging","syslog","syslog-client","syslog-logger","syslog-logging","tcp-syslog","tcp-syslog-client"],"install":[{"cmd":"npm install syslog-client","lang":"bash","label":"npm"},{"cmd":"yarn add syslog-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add syslog-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is primarily a CommonJS module. Direct ESM import might not work as expected and would require a bundler or specific Node.js loader configuration.","wrong":"import syslog from 'syslog-client';","symbol":"syslog","correct":"const syslog = require('syslog-client');"},{"note":"The `createClient` function is a property of the main `syslog` object exported via CommonJS `require`.","wrong":"import { createClient } from 'syslog-client';","symbol":"createClient","correct":"const client = syslog.createClient('127.0.0.1');"},{"note":"Constants like `Transport`, `Facility`, and `Severity` are nested objects under the main `syslog` export and should be accessed as `syslog.Transport.Udp`.","wrong":"import { Transport } from 'syslog-client';","symbol":"Transport, Facility, Severity","correct":"const transport = syslog.Transport.Udp; // Similarly for Facility and Severity"}],"quickstart":{"code":"const os = require('os');\nconst syslog = require('syslog-client');\n\nconst options = {\n  syslogHostname: os.hostname(),\n  transport: syslog.Transport.Udp,\n  port: 514,\n  facility: syslog.Facility.Local0,\n  severity: syslog.Severity.Informational,\n  rfc3164: true // Defaults to RFC 3164\n};\n\n// Create a syslog client targeting localhost via UDP\nconst client = syslog.createClient('127.0.0.1', options);\n\nclient.log('This is an example syslog message from my Node.js application.', {}, (error) => {\n  if (error) {\n    console.error('Failed to send syslog message:', error);\n  } else {\n    console.log('Syslog message sent successfully.');\n  }\n  client.close(); // Close the client connection if TCP is used or to clean up resources\n});\n\n// Example with custom severity\nclient.log('An important warning occurred!', {\n  severity: syslog.Severity.Warning,\n  facility: syslog.Facility.User\n}, (error) => {\n  if (error) console.error('Warning message failed:', error);\n  else console.log('Warning message sent.');\n});","lang":"javascript","description":"This quickstart demonstrates how to initialize a syslog client, send basic log messages, and specify custom options like severity and facility. It highlights the use of `createClient` and the `log` method with callbacks for error handling."},"warnings":[{"fix":"When creating the client, pass `{ rfc3164: false }` in the options object: `syslog.createClient('127.0.0.1', { rfc3164: false });`","message":"By default, the client sends messages formatted according to RFC 3164. If you require the newer RFC 5424 format, you must explicitly set the `rfc3164` option to `false` in the `createClient` options object.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Specify the `transport` and `port` options: `syslog.createClient('127.0.0.1', { transport: syslog.Transport.Tcp, port: 6514 });`","message":"The package defaults to using UDP transport on port 514. If your syslog server expects TCP or a different port, these must be explicitly configured in the client options.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Adjust `tcpTimeout` in the client options to suit your network environment: `syslog.createClient('127.0.0.1', { transport: syslog.Transport.Tcp, tcpTimeout: 5000 });`","message":"The `tcpTimeout` option, defaulting to 10 seconds, controls both connection attempts and TCP acknowledgement waits. This default might be too long for highly responsive systems or too short for unreliable network conditions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For new projects or critical applications, consider evaluating more modern and actively maintained syslog client libraries for Node.js, such as `@resqclub/syslog-client` or `@n8n/syslog-client`, or the `winston-syslog` transport if using Winston.","message":"This package has not been updated in approximately 9 years. While it may still function for basic syslog needs, it might lack modern features, performance optimizations, or security patches found in more actively maintained alternatives.","severity":"gotcha","affected_versions":"<=1.1.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure the syslog server (e.g., rsyslog, syslog-ng) is running on the target machine and configured to listen on the specified port and protocol. Check firewall rules on both the client and server. For TCP, ensure the server is configured to accept TCP connections.","cause":"The syslog server at the specified target IP and port is not running or is blocking connections.","error":"Error: connect ECONNREFUSED"},{"fix":"Use the CommonJS `require` syntax as demonstrated in the documentation: `const syslog = require('syslog-client');` and then access `syslog.createClient()`. If using TypeScript with `esModuleInterop` enabled, `import syslog from 'syslog-client';` might work, but direct named imports are generally not supported for pure CJS modules.","cause":"This error typically occurs when attempting to use ESM `import { createClient } from 'syslog-client'` with a CommonJS-only module, or incorrectly destructuring the `require` output.","error":"TypeError: syslog.createClient is not a function"},{"fix":"Verify the `target` IP address and `port` in `createClient`. Confirm the `transport` (UDP/TCP) matches the server's configuration. Check the syslog server's configuration (`/etc/rsyslog.conf` or `/etc/syslog-ng/syslog-ng.conf`) for any filtering rules that might be discarding messages based on facility, severity, program name, or source host. Temporarily increase verbosity on the server or use a network packet analyzer like Wireshark/tcpdump.","cause":"This can be due to incorrect IP address, port, transport protocol, or facility/severity filtering on the syslog server.","error":"Message not appearing in syslog server logs."}],"ecosystem":"npm"}