logging

package
v0.0.0-...-0d458a7 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logging provides a custom slog handler with colored, human-readable output.

Index

Constants

View Source
const LevelVerbose = slog.Level(-2)

LevelVerbose sits between INFO and DEBUG for detailed progress messages.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler implements slog.Handler with the format:

LEVEL   TIMESTAMP [target] message key=value ...

func NewHandler

func NewHandler(w io.Writer, opts *Options) *Handler

NewHandler creates a Handler that writes to w. Color is auto-detected when w is os.Stderr (or any *os.File with a terminal fd).

func (*Handler) Enabled

func (h *Handler) Enabled(_ context.Context, level slog.Level) bool

Enabled reports whether the handler handles records at the given level.

func (*Handler) Handle

func (h *Handler) Handle(_ context.Context, r slog.Record) error

Handle formats and writes a log record.

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new Handler with the given attrs pre-attached.

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

WithGroup returns a new Handler with the given group name.

type MultiHandler

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

MultiHandler fans out log records to multiple slog.Handler implementations. Each child handler maintains its own writer, mutex, and settings.

func NewMultiHandler

func NewMultiHandler(handlers ...slog.Handler) *MultiHandler

NewMultiHandler creates a handler that writes to all provided handlers.

func (*MultiHandler) Enabled

func (m *MultiHandler) Enabled(ctx context.Context, level slog.Level) bool

Enabled returns true if any child handler is enabled at the given level.

func (*MultiHandler) Handle

func (m *MultiHandler) Handle(ctx context.Context, r slog.Record) error

Handle writes the record to all enabled child handlers.

func (*MultiHandler) WithAttrs

func (m *MultiHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs returns a new MultiHandler with attrs applied to each child.

func (*MultiHandler) WithGroup

func (m *MultiHandler) WithGroup(name string) slog.Handler

WithGroup returns a new MultiHandler with the group applied to each child.

type Options

type Options struct {
	// Level is the minimum log level to emit.
	Level slog.Leveler
	// NoColor forces color off regardless of TTY detection.
	NoColor bool
}

Options configures the Handler.

Jump to

Keyboard shortcuts

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