logging

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package logging configures log/slog for the process.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(w io.Writer, level, format string) *slog.Logger

New returns a logger writing to w in the given format ("json" or "text") at the given level ("debug", "info", "warn", "error").

func ParseLevel

func ParseLevel(s string) slog.Level

ParseLevel maps a level name to a slog.Level, defaulting to info.

func SetCaller

func SetCaller(ctx context.Context, caller string)

SetCaller names who makes a request: "user:<id>", "key:<id>" or "agent:<id>". Never a name or an email.

func SetWorkspace

func SetWorkspace(ctx context.Context, slug string)

SetWorkspace names the workspace a request acts in (its slug).

func WithJob

func WithJob(ctx context.Context, job string) context.Context

WithJob starts a background job's fields ("kind:id").

func WithRequest

func WithRequest(ctx context.Context, requestID string, route func() string) context.Context

WithRequest starts a request's fields. route reads the route pattern (known only once routing is done), and may be nil.

Types

type ContextHandler

type ContextHandler struct{ slog.Handler }

ContextHandler adds the context's request or job fields to each record.

func (ContextHandler) Handle

func (h ContextHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements slog.Handler.

func (ContextHandler) WithAttrs

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

WithAttrs implements slog.Handler.

func (ContextHandler) WithGroup

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

WithGroup implements slog.Handler.

type Fields

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

Fields are what a request's log lines say about it. They are filled in as the request goes through the stack, so they are read under a lock.

func FieldsFrom

func FieldsFrom(ctx context.Context) *Fields

FieldsFrom returns the fields of ctx's request or job, or nil.

func (*Fields) Attrs

func (f *Fields) Attrs() []slog.Attr

Attrs returns the fields as log attributes, leaving out the empty ones.

Jump to

Keyboard shortcuts

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