selflog

package
v0.13.30 Latest Latest
Warning

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

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

Documentation

Overview

Package selflog is agnt's always-on persistent log for its OWN fire-and-forget failures — the errors that, by design, must stay silent to their caller and so would otherwise vanish.

Unlike internal/debug (which only writes when debug mode is enabled), selflog always writes, to a single rotating file at ${XDG_CACHE_HOME:-$HOME/.cache}/agnt/errors.log. The two writers that matter most run when the daemon is unreachable — the `agnt hook` dispatcher (a separate short-lived process) and the incident pinger — so the log is file-based with no daemon dependency: the viewer command (`agnt hook log`) and the overlay status notice both read it directly, and it works even with the daemon down.

The package is a leaf (no agnt imports) so the latency-budgeted hook dispatcher and the import-cycle-sensitive overlay can both use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear(path string) error

Clear removes the log (and its rotated generation). A missing file is not an error.

func CountSince

func CountSince(path string, t time.Time) (int, error)

CountSince returns how many entries have a timestamp at or after t. Used by the overlay to decide whether to raise a status-bar notice. A missing file counts as zero.

func DefaultPath

func DefaultPath() string

DefaultPath resolves the persistent error-log location. AGNT_ERROR_LOG wins (tests and power users redirect with one env var); otherwise it follows the XDG cache convention, matching internal/debug's log dir.

func Record

func Record(component, format string, args ...any)

Record appends one self-error to the default log. Component is a space-free token identifying the source (e.g. "hook", "pinger"). Write failures are deliberately swallowed — the caller is already on a failure path and a failing log write must never escalate.

func RecordTo

func RecordTo(path, component, message string)

RecordTo appends one record to an explicit path. Used by callers that inject the path (the hook dispatcher honours its --drop-log / test override). A trailing rotation keeps the file bounded.

Types

type Entry

type Entry struct {
	Time      time.Time
	Component string
	Message   string
}

Entry is one parsed self-error record.

func Read

func Read(path string, limit int) ([]Entry, error)

Read returns the most recent up-to-limit entries from the log at path, oldest-first. A missing file is not an error (returns nil). limit <= 0 returns all entries.

Jump to

Keyboard shortcuts

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