logsink

package
v2.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package logsink provides a shared Unix-domain-socket writer for Alpamon plugins. Plugins use this package as an io.Writer target for zerolog so that their logs are forwarded to Alpamon and then on to the Alpacon server, without each plugin duplicating the filtering, framing, and reconnect logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SocketPath

func SocketPath() string

SocketPath returns the UDS path for the Alpamon log socket.

The path is derived from utils.RunDir(), which differs by uid: /run/alpamon for root, /tmp/alpamon for non-root. This is safe today because both Alpamon and its plugins run as root; once privilege separation lands, this should switch to a fixed system path so non-root plugins still reach the daemon's socket.

Types

type Writer

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

Writer is a zerolog-compatible io.Writer that forwards filtered log records to alpamon over a Unix domain socket using the length-prefix wire protocol.

Each Write call parses the zerolog JSON line, checks whether the source file and level pass the plugin-specific handlers filter, builds a LogRecord, and sends it framed as [uint32 BE length][JSON body]. Connection errors are silent and the writer reconnects automatically after a short cooldown.

func New

func New(program string, handlers map[string]int) *Writer

New returns a Writer for the given plugin. program is used as the LogRecord.Program field. handlers maps base filenames to their minimum log level threshold (using Python logging levels: 10=DEBUG, 20=INFO, 30=WARNING, 40=ERROR, 50=CRITICAL). Connection failure at construction time is non-fatal; the writer will retry.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the underlying connection.

func (*Writer) Write

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

Write implements io.Writer. p is expected to be a single zerolog JSON line. Always returns (len(p), nil) to prevent zerolog from logging internal errors.

Jump to

Keyboard shortcuts

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