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.
Basic usage with default options
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
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
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
options: SyslogSinkOptions
Configuration options for the syslog sink
https://tools.ietf.org/html/rfc5424 RFC 5424 - The Syslog Protocol
SyslogSinkOptions for detailed configuration options