applog

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package applog provides logging for cliamp.

Two sinks are layered behind one API:

  • A file sink, written through log/slog, for diagnostic logs the user reads after the fact (~/.config/cliamp/cliamp.log).
  • An in-memory ring buffer drained by the TUI footer for short-lived, user-facing messages. The buffer exists because writing to stderr would corrupt the TUI.

Callers pick by intent, not sink:

  • Debug/Info/Warn/Error write only to the file.
  • Status writes only to the footer (transient UI feedback that wouldn't help post-mortem debugging).
  • UserWarn/UserError write to both.

Init must be called once at startup. Calls before Init are silently dropped on the file side; the footer buffer always works.

Index

Constants

View Source
const (
	LevelDebug = slog.LevelDebug
	LevelInfo  = slog.LevelInfo
	LevelWarn  = slog.LevelWarn
	LevelError = slog.LevelError
)

Variables

This section is empty.

Functions

func Debug

func Debug(format string, args ...any)

Debug, Info, Warn, Error log only to the file. Format follows fmt.Sprintf. The level guard avoids paying the Sprintf cost when the level is filtered out.

func Error

func Error(format string, args ...any)

func Info

func Info(format string, args ...any)

func Init

func Init(path string, level Level) (func() error, error)

Init opens path for append, installs a slog text handler at the given level, and returns a close func. Calling Init twice closes the previous file before swapping handlers.

func Status

func Status(format string, args ...any)

Status pushes a message into the footer buffer without writing to the log file. Use for ephemeral, user-facing notifications that wouldn't help post-mortem debugging.

func UserError

func UserError(format string, args ...any)

UserError logs at error level and pushes the same message into the footer.

func UserWarn

func UserWarn(format string, args ...any)

UserWarn logs at warn level and pushes the same message into the footer. The Sprintf cost is paid unconditionally because the footer needs the formatted string, so no Enabled gate here.

func Warn

func Warn(format string, args ...any)

Types

type Entry

type Entry struct {
	Text string
	At   time.Time
}

Entry is a single footer message with a timestamp.

func Drain

func Drain() []Entry

Drain returns and clears all buffered footer entries.

type Level

type Level = slog.Level

Level is an alias for slog.Level so callers don't need a second import.

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel maps a string to a Level. Empty input maps to LevelInfo. "warning" is accepted as an alias for "warn".

Jump to

Keyboard shortcuts

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