logsource

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package logsource gives a single, filtered view over every log lerd can reach: framework application log files, PHP-FPM/nginx/dns/service container stdout, and worker/watcher/ui units (systemd journal on Linux, launchd log files on macOS). It wraps the existing readers (internal/applog, podman logs, journalctl) behind one Source registry + Read dispatcher so callers — the MCP `logs` tool, the `diag.logs` alias — never reimplement log access.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FPMContainer

func FPMContainer(site *config.Site) string

FPMContainer resolves the container that serves a site: its own custom / FrankenPHP / custom-FPM container when applicable, otherwise the shared lerd-php<version>-fpm. Returns "" for host-proxy sites, which run no container. Mirrors cli.resolveWorkerFPMUnit so logs target the same place workers exec into.

func StripANSI

func StripANSI(s string) string

StripANSI removes ANSI escape sequences from log output.

Types

type Entry

type Entry struct {
	Time    string `json:"time,omitempty"`
	Level   string `json:"level,omitempty"`
	Channel string `json:"channel,omitempty"`
	Text    string `json:"text"`
}

Entry is one normalised log line. Time/Level/Channel are populated when the backend exposes them (monolog files, journal); container stdout fills Text only.

type Kind

type Kind int

Kind is the physical backend a Source is read from.

const (
	KindFile    Kind = iota // application log file on disk (real timestamps)
	KindPodman              // container stdout via `podman logs`
	KindJournal             // systemd journal (Linux) / launchd log file (macOS)
)

func (Kind) String

func (k Kind) String() string

type Opts

type Opts struct {
	Since string // relative ("15m", "2h30m"), absolute timestamp, or a prior Cursor
	Until string // upper time bound (same formats)
	Grep  string // regex, falling back to a literal substring when it won't compile
	Lines int    // tail cap (default 50)
	Level string // KindFile/monolog only: error, warning, info, debug…
}

Opts are the filters applied to a fetch. Empty fields are ignored.

type Result

type Result struct {
	Entries   []Entry
	Cursor    string
	Truncated bool
}

Result is a window of entries in chronological order (oldest first, newest last). Cursor is the newest entry's opaque position — pass it back as Opts.Since on the next call to fetch only newer lines.

func Read

func Read(src Source, opts Opts) (Result, error)

Read fetches a filtered window from a single source, dispatching on its kind.

func (Result) Lines

func (r Result) Lines() []string

Lines returns just the text of each entry, oldest first.

type Scope

type Scope string

Scope distinguishes per-site sources from shared infrastructure.

const (
	ScopeSite   Scope = "site"
	ScopeGlobal Scope = "global"
)

type Source

type Source struct {
	Name    string
	Kind    Kind
	Locator string
	Scope   Scope
	Format  string // "monolog"|"raw" for KindFile, empty otherwise
	Label   string
}

Source is one addressable log stream. Locator is a file path (KindFile), a container name (KindPodman), or a unit name (KindJournal).

func Resolve

func Resolve(siteName, sitePath, name string) (Source, error)

Resolve looks up a single source by name within the current context. It resolves the deterministic names (fpm, worker:*, globals) directly so a fetch doesn't pay for a full Sources() enumeration (framework resolution, log-file globbing, installed-PHP discovery); only app:* files and the unknown-name error path fall back to the full listing.

func Sources

func Sources(siteName, sitePath string) ([]Source, error)

Sources enumerates every queryable source for the given site context plus the always-present global infrastructure sources. Either siteName or sitePath may be empty; when neither resolves to a registered site only globals are returned.

Jump to

Keyboard shortcuts

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