syslog

package
v1.0.126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package syslog forwards log lines to a remote syslog server over UDP or TCP. It is a self-contained leaf (stdlib only, no Culvert coupling) extracted from the flat package main per ADR-0002. The structured-entry writers take `any` (the entry is only JSON-marshalled) so the forwarder needn't know the concrete audit/request-log struct types.

Two formats are supported:

RFC 3164 (BSD syslog) — legacy, accepted everywhere.
RFC 5424 (IETF syslog) — modern SIEMs prefer this for structured data,
  microsecond timestamps, and proper UTF-8 BOM handling.

Priority: facility=1 (user-level), severity=6 (informational) → PRI=14. Audit events are sent at severity=5 (notice) → PRI=13.

Delivery is ASYNCHRONOUS: senders format the line and enqueue it on a bounded channel; a single drain goroutine (started by NewWriter) owns the connection, the reconnect/backoff state machine, and every network write. The request path therefore never takes the connection mutex and never blocks on a socket — a slow or wedged TCP collector costs the caller a channel send, with overflow counted in Drops rather than propagated as proxy latency. Ordering is preserved (one drain goroutine).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer forwards log lines to a remote syslog server over UDP or TCP.

A Writer built by NewWriter delivers asynchronously via queue/drainLoop; a zero-value Writer (tests build these directly) has a nil queue and falls back to the synchronous writeMsg path, so the delivery state machine stays directly testable.

func NewWriter

func NewWriter(network, addr, format string) (*Writer, error)

NewWriter dials the syslog server and returns a ready Writer. format selects the wire format: "rfc3164" (default) or "rfc5424".

func (*Writer) Close

func (s *Writer) Close() error

Close stops the drain goroutine (flushing already-queued lines within flushTimeout) and releases the connection. Idempotent; concurrent sends after Close count as drops. On an async Writer the connection is owned and released by the drain goroutine; Close waits up to closeWait for it — if a wedged collector outlasts even that, Close returns and the goroutine releases the conn when its write deadline fires.

func (*Writer) Drops added in v1.0.39

func (s *Writer) Drops() uint64

Drops reports the number of messages dropped because the collector was unreachable or not draining, the delivery queue overflowed, or the Writer was already closed. Monotonic per Writer; delivery is otherwise silent-best-effort, so this is the only loss signal.

func (*Writer) Format

func (s *Writer) Format() string

Format returns the syslog message format ("rfc3164" or "rfc5424").

func (*Writer) Write

func (s *Writer) Write(p []byte) (int, error)

Write implements io.Writer. Each call is a single syslog message at PRI=14.

func (*Writer) WriteAudit

func (s *Writer) WriteAudit(e any)

WriteAudit sends a structured audit entry as a JSON syslog message at severity=5 (notice), which most SIEMs map to a security-relevant priority. The entry is only JSON-marshalled, so any serializable value is accepted.

func (*Writer) WriteRequest

func (s *Writer) WriteRequest(e any)

WriteRequest sends a structured request-log entry as a JSON syslog message at PRI=14 (facility=1 user-level, severity=6 informational).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL