source

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package source defines the LogLine type and the Source interface that file, docker and journal backends implement. A simple Hub helper provides fan-out so multiple jails can subscribe to the same source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

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

Hub is a reusable fan-out helper for Source implementations.

func NewHub

func NewHub() *Hub

NewHub returns an empty Hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(line LogLine) int

Broadcast delivers line to every subscriber. If a subscriber's buffer is full the line is dropped for that subscriber (logged by caller if desired). Returns the number of subscribers that received the line.

func (*Hub) Close

func (h *Hub) Close()

Close closes all subscriber channels.

func (*Hub) Subscribe

func (h *Hub) Subscribe(name string, bufSize int) <-chan LogLine

Subscribe registers a named subscriber and returns its channel. If a subscriber with the same name already exists the existing channel is returned.

func (*Hub) SubscriberCount

func (h *Hub) SubscriberCount() int

SubscriberCount returns the number of currently-registered subscribers.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(name string)

Unsubscribe removes a named subscriber and closes its channel. Used by daemon.Reload when a rule is removed from config — the rule's goroutine sees the channel close (its `range in` loop terminates) and the source's Broadcast no longer publishes to a dead consumer.

Safe to call on an unknown name (no-op) and on an already-removed subscriber (no double-close — we check membership before closing).

type LogLine

type LogLine struct {
	Source    string    // source name (e.g. "auth-log")
	Container string    // populated by docker source
	Unit      string    // populated by journal source
	Text      string    // the raw line, trimmed of trailing newline
	Time      time.Time // event time if available, else producer wall time
}

LogLine is a single line of log output ready to be matched.

type Source

type Source interface {
	// Name returns the user-configured source name.
	Name() string
	// Start begins producing lines; safe to call once. ctx cancellation
	// terminates the source.
	Start(ctx context.Context) error
	// Subscribe returns a receive-only channel of LogLine. Multiple
	// subscribers each receive every line. Buffered to absorb spikes.
	Subscribe(name string, bufSize int) <-chan LogLine
	// Unsubscribe removes a named subscriber, closing its channel so the
	// consuming goroutine's `range` over it terminates cleanly. Safe to
	// call on an unknown name (no-op).
	Unsubscribe(name string)
	// Close releases resources.
	Close() error
}

Source is the read side of a log stream. Subscribe returns a channel that receives LogLine values until the Source is shut down via Close or its internal context is cancelled.

Directories

Path Synopsis
Package docker implements a Source that streams container logs from the Docker daemon and dynamically attaches to new containers matching a label or name selector.
Package docker implements a Source that streams container logs from the Docker daemon and dynamically attaches to new containers matching a label or name selector.
Package file implements a Source backed by a tailed file with rotation support.
Package file implements a Source backed by a tailed file with rotation support.
Package journal provides a systemd-journal log source.
Package journal provides a systemd-journal log source.

Jump to

Keyboard shortcuts

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