journald

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package journald is the journald log source: systemd journal files under the console's read-only journal roots, read by the pure-Go reader in ./journal, with a field allowlist applied before any value is read.

Only MESSAGE (decoded by the source's parser, masked as text downstream) and the allowed fields (the trusted journald fields, the human's trusted fields and the reviewed allow list) ever leave this package. Core dumps, command lines, executables, audit and OBJECT_ fields and binary values are dropped whatever the lists say.

Index

Constants

View Source
const (
	// GranuleEntries is the size of a plan granule: fixed groups of
	// entries of one file, in file order, independent of any query.
	GranuleEntries = 256
	// MaxAround bounds before and after of Around.
	MaxAround = 50
)
View Source
const Kind = "journald"

Kind is the source kind.

Variables

View Source
var Trusted = []string{"CODE_FILE", "CODE_FUNC", "CODE_LINE", "CONTAINER_NAME", "PRIORITY",
	"SYSLOG_IDENTIFIER", "_HOSTNAME", "_PID", "_SYSTEMD_UNIT", "_TRANSPORT"}

Trusted are the journald fields locklog always serves (after the detectors), besides MESSAGE.

Functions

func NeverServed

func NeverServed(name string) bool

NeverServed reports a field no list can make this source serve: core dumps, command lines, executables, audit records and OBJECT_ fields.

Types

type Options

type Options struct {
	Name string
	// Roots are the journal roots mounted read-only (/var/log/journal,
	// /run/log/journal): each holds <machine-id>/ directories.
	Roots []string
	// Units are globs on _SYSTEMD_UNIT; empty serves every unit.
	Units []string
	// Trusted are the human's trusted fields beyond Trusted; Allow the
	// reviewed fields served (masked) besides MESSAGE and the trusted ones.
	Trusted []string
	Allow   []string
	// UserJournals also serves user-*.journal files.
	UserJournals bool
	// Parser decodes MESSAGE (format of the message).
	Parser *parse.Parser
	// Now is the clock (tests).
	Now func() time.Time
}

Options configure a journald source.

type Source

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

Source is a journald source. It is safe for concurrent use.

func New

func New(opts Options) (*Source, error)

New validates opts.

func (*Source) Around

func (s *Source) Around(ctx context.Context, ref source.RawRef, before, after int) ([]source.RawRecord, error)

Around returns up to before served entries before ref, ref's entry and up to after served entries after it, from ref's file.

func (*Source) Describe

func (s *Source) Describe(ctx context.Context) (source.Schema, error)

Describe returns the source's fields, file count, size and time bounds. It reads headers only.

func (*Source) Kind

func (s *Source) Kind() string

Kind returns "journald".

func (*Source) Name

func (s *Source) Name() string

Name returns the source name.

func (*Source) Plan

Plan returns, per file, one chunk per run of consecutive granules that may hold entries of r, judged on each granule's true time bounds (every entry's timestamp), so clock steps inside a file never drop an entry.

func (*Source) Reread

func (s *Source) Reread(ctx context.Context, ref source.RawRef) (source.RawRecord, error)

Reread returns the entry at ref.Offset in ref's stream, or ErrStale when the file is gone or no longer holds that entry there.

func (*Source) Scan

func (s *Source) Scan(ctx context.Context, c source.Chunk) (source.Iterator, error)

Scan reads the entries of a chunk: entry indexes [Start, End) of its granules, in file order.

Directories

Path Synopsis
Package journal reads systemd journal files (the format of systemd's JOURNAL_FILE_FORMAT.md): regular and compact layouts, XZ, LZ4 and ZSTD compressed data objects, keyed or Jenkins hashes.
Package journal reads systemd journal files (the format of systemd's JOURNAL_FILE_FORMAT.md): regular and compact layouts, XZ, LZ4 and ZSTD compressed data objects, keyed or Jenkins hashes.
journaltest
Package journaltest builds small journal files in memory for tests and fuzz seeds: header, DATA, ENTRY and chained ENTRY_ARRAY objects, regular or compact, plain or ZSTD/LZ4/XZ compressed (no hash tables: the reader does not use them).
Package journaltest builds small journal files in memory for tests and fuzz seeds: header, DATA, ENTRY and chained ENTRY_ARRAY objects, regular or compact, plain or ZSTD/LZ4/XZ compressed (no hash tables: the reader does not use them).

Jump to

Keyboard shortcuts

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