logging

package
v0.29.0 Latest Latest
Warning

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

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

Documentation

Overview

Package logging provides an slog.Handler that fans a record out to several handlers, each with its own independent level filter. It exists so cargoship can write every log level to a file for later debugging while the terminal keeps showing only what the user's configured --log-level asks for.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenFileHandler

func OpenFileHandler(path string) (slog.Handler, *os.File, error)

OpenFileHandler opens (creating if needed) the file at path and returns an slog.Handler that writes every level -- Debug and up, i.e. all of them -- to it as JSON. The caller owns the returned file and must close it once logging is done.

Types

type MultiHandler

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

MultiHandler dispatches each log record to every handler that wants it. Unlike wrapping a single slog.Logger, each handler keeps its own Enabled check: one handler can be silent at Info while another still records everything down to Debug.

func NewMultiHandler

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

NewMultiHandler returns a MultiHandler that fans records out to handlers.

func (*MultiHandler) Enabled

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

Enabled reports whether at least one handler wants records at level. This must stay a logical OR: the top-level slog.Logger calls Enabled before Handle, so if this returned false whenever any single handler would refuse the level, that handler would silence every other handler in the group along with it -- including a file handler meant to catch everything.

func (*MultiHandler) Handle

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

Handle passes r to every handler whose own Enabled check accepts r.Level.

func (*MultiHandler) WithAttrs

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

WithAttrs returns a MultiHandler whose children each have attrs added.

func (*MultiHandler) WithGroup

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

WithGroup returns a MultiHandler whose children each have the group added.

Jump to

Keyboard shortcuts

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