log

package
v1.84.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 17 Imported by: 5

Documentation

Index

Constants

View Source
const ExtractorErrorKey = "log.extractor_error"

ExtractorErrorKey is where a record says that an extractor failed on it: among the log's own fields, as the size guard's truncation marker is, rather than under error, which is the error the record is about. A single key, not a group, so that it cannot meet another group of that name in one entry.

Variables

This section is empty.

Functions

func AttrsFromMap

func AttrsFromMap(m map[string]any) []any

Types

type ContextExtractor

type ContextExtractor interface {
	Handle(context.Context, *slog.Record) error
}

type ContextExtractorFunction

type ContextExtractorFunction func(context.Context, *slog.Record) error

func (ContextExtractorFunction) Handle

func (cef ContextExtractorFunction) Handle(ctx context.Context, record *slog.Record) error

type ContextHandler

type ContextHandler struct {
	Next       slog.Handler
	Extractors []ContextExtractor
}

func (*ContextHandler) Enabled

func (contextHandler *ContextHandler) Enabled(ctx context.Context, level slog.Level) bool

func (*ContextHandler) Handle

func (contextHandler *ContextHandler) Handle(ctx context.Context, record slog.Record) error

Handle runs the extractors before passing the record on. One that fails costs the record what that extractor would have added, never the record itself: what it did add is taken back, unless it vouches for that by returning a PartialExtractionError itself, and the failure is recorded under ExtractorErrorKey. The message is not taken back: an extractor may have masked it, and taking that back would put back what was masked.

func (*ContextHandler) WithAttrs

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

WithAttrs returns a handler of its own, as slog requires: changing this one would hand the attributes to every logger that shares it, and to every record logged after, while those loggers read it from other goroutines.

func (*ContextHandler) WithGroup

func (contextHandler *ContextHandler) WithGroup(name string) slog.Handler

WithGroup returns a handler of its own, for the reason WithAttrs does.

type ErrorContextExtractor

type ErrorContextExtractor struct {
	SkipCause         bool
	SkipInput         bool
	SkipStackTrace    bool
	SkipOutput        bool
	ContextExtractors []ContextExtractor
}

func (*ErrorContextExtractor) Handle

func (extractor *ErrorContextExtractor) Handle(ctx context.Context, record *slog.Record) error

func (*ErrorContextExtractor) MakeErrorAttrs

func (extractor *ErrorContextExtractor) MakeErrorAttrs(err error) []any

type PartialExtractionError added in v1.83.0

type PartialExtractionError struct {
	Err error
}

PartialExtractionError is an extractor's failure to add some of what it would have, reported with what it did add vouched for: the handler keeps the extractor's fields and records the failure, where it otherwise takes them back.

func (*PartialExtractionError) Error added in v1.83.0

func (e *PartialExtractionError) Error() string

func (*PartialExtractionError) Unwrap added in v1.83.0

func (e *PartialExtractionError) Unwrap() error

Directories

Path Synopsis
journal_handler
Package journal_handler adapts slog to the systemd journal, recording each record as one journal entry whose priority follows the record's level.
Package journal_handler adapts slog to the systemd journal, recording each record as one journal entry whose priority follows the record's level.
Package http_logger makes the logger an HTTP service logs through: JSON entries carrying what is known about the request being logged, which the service's own logging calls need say nothing about.
Package http_logger makes the logger an HTTP service logs through: JSON entries carrying what is known about the request being logged, which the service's own logging calls need say nothing about.
Package journal writes entries to the local systemd journal over its native protocol.
Package journal writes entries to the local systemd journal over its native protocol.

Jump to

Keyboard shortcuts

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