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 ¶
- type Collector
- func (c *Collector) Archives() []string
- func (c *Collector) Counts() (warn, errc int)
- func (c *Collector) Enabled(_ context.Context, l slog.Level) bool
- func (c *Collector) Entries() []Entry
- func (c *Collector) Handle(_ context.Context, r slog.Record) error
- func (c *Collector) WithAttrs([]slog.Attr) slog.Handler
- func (c *Collector) WithGroup(string) slog.Handler
- type ConsoleControl
- type Controls
- type Entry
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 ¶
Archives returns the distinct, non-empty archive names that produced a warning or error.
func (*Collector) Enabled ¶
Enabled reports whether the collector records the given level (WARN and above).
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