Skip to main content
Home

Built and signed on GitHub Actions

LogTape syslog sink

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
2 weeks ago (1.0.4)
function getSyslogSink
getSyslogSink(options?: SyslogSinkOptions): Sink & AsyncDisposable

Creates a syslog sink that sends log messages to a syslog server using the RFC 5424 syslog protocol format.

This sink supports both UDP and TCP protocols for reliable log transmission to centralized logging systems. It automatically formats log records according to RFC 5424 specification, including structured data support for log properties.

Features

  • RFC 5424 Compliance: Full implementation of the RFC 5424 syslog protocol
  • Cross-Runtime Support: Works with Deno, Node.js, Bun, and browsers
  • Multiple Protocols: Supports both UDP (fire-and-forget) and TCP (reliable) delivery
  • Structured Data: Automatically includes log record properties as RFC 5424 structured data
  • Facility Support: All standard syslog facilities (kern, user, mail, daemon, local0-7, etc.)
  • Automatic Escaping: Proper escaping of special characters in structured data values
  • Connection Management: Automatic connection handling with configurable timeouts

Protocol Differences

  • UDP: Fast, connectionless delivery suitable for high-throughput logging. Messages may be lost during network issues but has minimal performance impact.
  • TCP: Reliable, connection-based delivery that ensures message delivery. Higher overhead but guarantees that log messages reach the server.

Examples

Basic usage with default options

import { configure } from "@logtape/logtape";
import { getSyslogSink } from "@logtape/syslog";

await configure({
  sinks: {
    syslog: getSyslogSink(),  // Sends to localhost:514 via UDP
  },
  loggers: [
    { category: [], sinks: ["syslog"], lowestLevel: "info" },
  ],
});

Custom syslog server configuration

import { configure } from "@logtape/logtape";
import { getSyslogSink } from "@logtape/syslog";

await configure({
  sinks: {
    syslog: getSyslogSink({
      hostname: "log-server.example.com",
      port: 1514,
      protocol: "tcp",
      facility: "mail",
      appName: "my-application",
      timeout: 10000,
    }),
  },
  loggers: [
    { category: [], sinks: ["syslog"], lowestLevel: "debug" },
  ],
});

Using structured data for log properties

import { configure, getLogger } from "@logtape/logtape";
import { getSyslogSink } from "@logtape/syslog";

await configure({
  sinks: {
    syslog: getSyslogSink({
      includeStructuredData: true,
      structuredDataId: "myapp@12345",
    }),
  },
  loggers: [
    { category: [], sinks: ["syslog"], lowestLevel: "info" },
  ],
});

const logger = getLogger();
// This will include userId and action as structured data
logger.info("User action completed", { userId: 123, action: "login" });
// Results in: <134>1 2024-01-01T12:00:00.000Z hostname myapp 1234 - [myapp@12345 userId="123" action="login"] User action completed

Parameters

optional
options: SyslogSinkOptions

Configuration options for the syslog sink

Return Type

Sink & AsyncDisposable

A sink function that sends log records to the syslog server, implementing AsyncDisposable for proper cleanup

See

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";
or

Import directly with a jsr specifier

import { getSyslogSink } from "jsr:@logtape/syslog";

Add Package

pnpm i jsr:@logtape/syslog
or (using pnpm 10.8 or older)
pnpm dlx jsr add @logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";

Add Package

yarn add jsr:@logtape/syslog
or (using Yarn 4.8 or older)
yarn dlx jsr add @logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";

Add Package

vlt install jsr:@logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";

Add Package

npx jsr add @logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";

Add Package

bunx jsr add @logtape/syslog

Import symbol

import { getSyslogSink } from "@logtape/syslog";