entry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package entry is the log behavior: the entries of the systemd journal of the host, read with journalctl on each Linux host. The Go package keeps the name entry, so it does not hide the standard library's log.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"log", "The entries of the systemd journal",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Logs),
	behavior.CLI,
	behavior.Platform(behavior.PlatformLinux, newLinux),
	behavior.Read("list", List).
		NotAFact("the entries are what journald holds now, not a fact of the host").
		Runs("journalctl").
		Describe("List the entries of the journal").
		Explain("Runs journalctl --output=json, the newest entries last: the last "+
			"100 unless lines says, of one unit when unit says, since a time when "+
			"since says, and at a priority or above when priority says. A priority "+
			"is its name, such as err or info. The hand-written log domain read the "+
			"Debian family only; this reads each Linux host that has journald.").
		Example("The newest entries", ListInput{}, []Entry{nginxEntry, sshdEntry},
			behavior.Prints("journalctl --output=json -n 100", nginx+"\n"+sshd+"\n"),
		).
		Example("The last entry of one unit at info or above",
			ListInput{Unit: "nginx.service", Lines: 1, Since: "1 hour ago", Priority: "info"},
			[]Entry{nginxEntry},
			behavior.Prints(
				"journalctl --output=json --unit=nginx.service --since=1 hour ago --priority=info -n 1",
				nginx+"\n",
			),
		).
		Fails("Lines below one", ListInput{Lines: -1}, "min").
		Fails("More than 10000 lines", ListInput{Lines: 10001}, "max").
		Fails("A priority that journald does not have", ListInput{Priority: "loud"}, "enum").
		Fails("A unit with a space in it", ListInput{Unit: "nginx service"}, "unit_name"),
))

Behavior is the entries of the systemd journal. They are what journald holds now, not a fact of the host, so journalctl reads them, not gohai. It runs on each Linux host; macOS has no journal, and reports skipped.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Timestamp string   `json:"timestamp"          doc:"When journald recorded it, in RFC 3339"`
	Unit      string   `json:"unit,omitempty"     doc:"The syslog identifier that wrote it"`
	Priority  Priority `json:"priority,omitempty" doc:"Its priority, by name. An entry that journald has no priority for has none"`
	Message   string   `json:"message"            doc:"The message"`
	PID       int      `json:"pid,omitempty"      doc:"The process that wrote it"`
}

Entry is one entry of the journal.

func List

func List(
	ctx context.Context,
	p Provider,
	in ListInput,
) ([]Entry, error)

List is the entries of the journal that in selects.

type ListInput

type ListInput struct {
	Unit     string   `` /* 129-byte string literal not displayed */
	Lines    int      `json:"lines,omitempty"    validate:"omitempty,min=1,max=10000" doc:"How many of the newest entries; 100 when it is not set"`
	Since    string   `` /* 164-byte string literal not displayed */
	Priority Priority `json:"priority,omitempty" validate:"omitempty,enum"            doc:"Only the entries at this priority or above"`
}

ListInput selects the entries: each field is a query parameter and a flag.

type Priority

type Priority string

Priority is the priority of a journal entry, by the name that journald gives it.

const (
	PriorityEmerg   Priority = "emerg"
	PriorityAlert   Priority = "alert"
	PriorityCrit    Priority = "crit"
	PriorityErr     Priority = "err"
	PriorityWarning Priority = "warning"
	PriorityNotice  Priority = "notice"
	PriorityInfo    Priority = "info"
	PriorityDebug   Priority = "debug"
)

The priorities of journald, from the highest.

func Priorities

func Priorities() []Priority

Priorities are the priorities in journald's order: the index of each is its number, 0 for emerg to 7 for debug.

func (Priority) Valid

func (p Priority) Valid() bool

Valid reports whether p is a priority of journald.

func (Priority) Values

func (Priority) Values() []Priority

Values are the priorities, for the enum rule.

type Provider

type Provider interface {
	// Entries is the entries that opts selects, the newest last.
	Entries(ctx context.Context, opts ListInput) ([]Entry, error)
}

Provider reads the journal of the host.

Directories

Path Synopsis
Package mocks holds the generated double of the entry provider, for the methods' tests.
Package mocks holds the generated double of the entry provider, for the methods' tests.

Jump to

Keyboard shortcuts

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