Syslog Client for Node.js

1.1.1 · maintenance · verified Tue Apr 21

`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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const os = require('os');
const syslog = require('syslog-client');

const options = {
  syslogHostname: os.hostname(),
  transport: syslog.Transport.Udp,
  port: 514,
  facility: syslog.Facility.Local0,
  severity: syslog.Severity.Informational,
  rfc3164: true // Defaults to RFC 3164
};

// Create a syslog client targeting localhost via UDP
const client = syslog.createClient('127.0.0.1', options);

client.log('This is an example syslog message from my Node.js application.', {}, (error) => {
  if (error) {
    console.error('Failed to send syslog message:', error);
  } else {
    console.log('Syslog message sent successfully.');
  }
  client.close(); // Close the client connection if TCP is used or to clean up resources
});

// Example with custom severity
client.log('An important warning occurred!', {
  severity: syslog.Severity.Warning,
  facility: syslog.Facility.User
}, (error) => {
  if (error) console.error('Warning message failed:', error);
  else console.log('Warning message sent.');
});

view raw JSON →