journal

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package journal reads a systemd unit's journal through a journalctl subprocess — no cgo, so the release matrix stays a plain cross-compile. Entries carry the journal's own timestamps (the first source with real event times) and a cursor, the durable resume position: restart with the saved cursor and nothing is re-read.

Index

Constants

View Source
const MaxLine = 1024 * 1024

MaxLine bounds one journal record's JSON encoding.

Variables

This section is empty.

Functions

func Command

func Command(ctx context.Context, unit, cursor string) *exec.Cmd

Command builds the journalctl invocation for one unit: follow mode, JSON output, resuming after cursor when one is known and starting at the present otherwise — a fresh input must not replay months of history as if it were happening now.

func Decode

func Decode(r io.Reader, emit func(Entry)) error

Decode reads JSON-line journal records and emits the well-formed ones. A malformed record is skipped — one broken line must not stop the stream — and reported in the returned count.

func Past

func Past(ctx context.Context, unit string, since time.Duration, emit func(Entry)) error

Past reads a unit's journal backwards in time rather than following it: everything since, or the whole journal when since is zero. It is what a replay uses, and unlike a file the journal carries each record's own timestamp already, so there is nothing to parse out of the text.

func Run

func Run(ctx context.Context, unit, cursor string, emit func(Entry)) error

Run starts journalctl for the unit and emits entries until the context ends or the subprocess dies. The caller restarts it with backoff and the last cursor.

Types

type Entry

type Entry struct {
	Time    time.Time
	Cursor  string
	Message string
	Unit    string
}

Entry is one journal record.

Jump to

Keyboard shortcuts

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