logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package logger provides a thin factory around the standard library log/slog for building the application logger.

New returns a logger that writes human-readable text to stderr and, when a log directory is given, structured JSON to a timestamped main log plus a WARN+ errors log in that directory. A small fan-out handler multiplexes records to every sink without any third-party dependency, keeping stdout free for data output and the progress bar.

Alongside the logger it returns Controls, which expose:

  • Console: a steerable console handler (writer + level). During an interactive run a command calls Console.SetTTYMode to route console output through the live progress display and raise the threshold to WARN (INFO still flows to the file), then Console.Restore afterwards.
  • Errors: a Collector slog.Handler that records every WARN+ event in memory so the command can show counts and affected archives in its end-of-run summary.
  • ErrorsPath: the on-disk WARN+ errors log (empty when no log dir).

Levels accepted (case-insensitive): debug, info, warn, error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector records every WARN+ record in memory and tallies counts.

func (*Collector) Archives

func (c *Collector) Archives() []string

Archives returns the distinct, non-empty archive names that produced a warning or error.

func (*Collector) Counts

func (c *Collector) Counts() (warn, errc int)

Counts returns the number of recorded warnings and errors.

func (*Collector) Enabled

func (c *Collector) Enabled(_ context.Context, l slog.Level) bool

Enabled reports whether the collector records the given level (WARN and above).

func (*Collector) Entries

func (c *Collector) Entries() []Entry

Entries returns a copy of all recorded WARN+ entries.

func (*Collector) Handle

func (c *Collector) Handle(_ context.Context, r slog.Record) error

Handle stores a WARN+ record and updates warning/error tallies.

func (*Collector) WithAttrs

func (c *Collector) WithAttrs([]slog.Attr) slog.Handler

WithAttrs implements slog.Handler; attributes are ignored for collection.

func (*Collector) WithGroup

func (c *Collector) WithGroup(string) slog.Handler

WithGroup implements slog.Handler; groups are ignored for collection.

type ConsoleControl

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

ConsoleControl steers the console handler at runtime.

func (*ConsoleControl) Restore

func (c *ConsoleControl) Restore()

Restore reverts the console writer to stderr and the level to its config value.

func (*ConsoleControl) SetTTYMode

func (c *ConsoleControl) SetTTYMode(w io.Writer)

SetTTYMode repoints console output at w (the live progress display) and, if the configured level is below WARN, raises it to WARN for the duration.

type Controls

type Controls struct {
	// Console steers the console handler's writer and level.
	Console *ConsoleControl
	// Errors accumulates every record at WARN or above.
	Errors *Collector
	// ErrorsPath is the on-disk errors log (empty when no log dir).
	ErrorsPath string
}

Controls exposes the runtime-steerable pieces of the logger

func New

func New(logLevel, logDir string) (*slog.Logger, *Controls, func() error, error)

New builds a *slog.Logger that writes human-readable text to stderr

type Entry

type Entry struct {
	Time    time.Time
	Level   slog.Level
	Message string
	Archive string // from the "name"/"label" attr when present
}

Entry is a single recorded warning/error.

Jump to

Keyboard shortcuts

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