WithExtractor (log/builder.go)

kratos · log/builder.go · go · MIT
infra

Configurable slog logger builder for Go applications with context extraction and filtering.

// Source: https://github.com/go-kratos/kratos | License: MIT | Copyright 2020 go-kratos
// Provided via justclaw.it.com; keep this notice with the code.
package log

import (
	"context"
	"io"
	"log/slog"
	"os"
)

// Format selects the encoding used by the default handler builder.
type Format int

const (
	// FormatText writes records using [slog.NewTextHandler].
	FormatText Format = iota
	// FormatJSON writes records using [slog.NewJSONHandler].
	FormatJSON
)

// Option configures [NewHandler] and the decorators applied by [NewLogger].
type Option func(*handlerConfig)

// Extractor extracts attrs from a log call context.
type Extractor func(context.Context) []slog.Attr

type handlerConfig struct {
	writer      io.Writer
	format      Format
	level       Leveler
	addSource   bool
	replaceAt

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key