sxcli.dev/fw/sink/syslog
import "sxcli.dev/fw/sink/syslog"
Package syslog provides the syslog log sink: a slog.Handler service writing records to the local syslog socket (default) or a remote syslog server. Under systemd the local socket is journald, so records land in journalctl with severity and tag intact — no dedicated journal protocol needed for ingestion. It is an ordinary service — cold until an applet requires it or the operator enables it:
import _ "sxcli.dev/fw/sink/syslog"
// then: mybox applet --enable syslogThe sink is unavailable on non-unix platforms: importing the package there is harmless and registers nothing.
Caveat: the stdlib syslog writer exposes no write deadlines, so a remote tcp target cannot fully honor the prompt-Handle sink contract; the local socket (the default) is unaffected.
Index#
- type Config
- type Syslog
- func (s *Syslog) Configured() error
- func (s *Syslog) Enabled(ctx context.Context, level slog.Level) bool
- func (s *Syslog) Handle(ctx context.Context, record slog.Record) error
- func (s *Syslog) Start() error
- func (s *Syslog) Stop() error
- func (s *Syslog) WithAttrs(attrs []slog.Attr) slog.Handler
- func (s *Syslog) WithGroup(name string) slog.Handler
type Config#
Config is the syslog sink configuration, section "syslog".
type Config struct { Level string `json:"level" arg:"syslog-level" usage:"minimum level logged to syslog (debug, info, warn, error)"` Format string `json:"format" arg:"syslog-format" usage:"syslog message format: text or json"` Tag string `json:"tag" arg:"syslog-tag" usage:"syslog tag; defaults to the process name"` Facility string `json:"facility" arg:"syslog-facility" usage:"syslog facility (daemon, user, auth, local0..local7, ...)"` Network string `json:"network" arg:"syslog-network" usage:"remote syslog network (udp, tcp); empty means the local socket"` Address string `json:"address" arg:"syslog-address" usage:"remote syslog address as host:port; set together with network"` }
type Syslog#
Syslog is the sink service. Severity travels per message, so Handle renders the record through the inner formatter into a guarded buffer and emits the line with the severity mapped from the record level. The formatter drops time= and level= — syslog stamps both itself.
type Syslog struct { // contains filtered or unexported fields }
func (*Syslog) Configured#
func (s *Syslog) Configured() error
Configured validates the configuration and — as its last act — dials the syslog socket and builds the inner formatter, so the sink is operational for the buffer replay at the multihandler swap.
func (*Syslog) Enabled#
func (s *Syslog) Enabled(ctx context.Context, level slog.Level) bool
Enabled reports whether the record would be logged; an unconfigured sink accepts nothing.
func (*Syslog) Handle#
func (s *Syslog) Handle(ctx context.Context, record slog.Record) error
Handle delegates to the shared delivery path.
func (*Syslog) Start#
func (s *Syslog) Start() error
Start is a no-op: the socket was dialed in Configured so the sink could capture the startup replay. The sink stays a Starter because only started Starters receive Stop.
func (*Syslog) Stop#
func (s *Syslog) Stop() error
Stop closes the syslog connection.
func (*Syslog) WithAttrs#
func (s *Syslog) WithAttrs(attrs []slog.Attr) slog.Handler
WithAttrs returns a derived view sharing the connection, per the sink-author contract.
func (*Syslog) WithGroup#
func (s *Syslog) WithGroup(name string) slog.Handler
WithGroup returns a derived view sharing the connection.