Help us shape the future of Go! Take the 2026 Go Developer Survey

logging

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package logging builds the application's structured logger (log/slog) and carries a per-request correlation id through context.

Wiring model: the process installs one configured logger as slog.Default via Setup, so every subsystem that already logs through slog — river, watermill (via NewSlogLogger), and the HTTP handlers — shares the same level, format, and sink without threading a *slog.Logger through every constructor. Request scoping is done via context (FromContext), not by injecting a logger.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext returns the default logger, tagged with the request id when the context carries one. Use this at request-scoped log sites so every line correlates back to the originating HTTP request.

func New

func New(cfg *config.Config) *slog.Logger

New builds a logger from config: a coloured, human-readable handler for LogFormat "text" (dev), otherwise structured JSON (prod). Level is one of debug|info|warn|error, defaulting to info for anything unrecognised.

func RequestIDFromContext

func RequestIDFromContext(ctx context.Context) (string, bool)

RequestIDFromContext returns the request id carried by ctx, if any.

func Setup

func Setup(cfg *config.Config)

Setup installs the configured logger as the process-wide slog default, so river, watermill, and every slog.Default() call site emit through it.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID returns a context carrying the request correlation id, so logs emitted downstream via FromContext are tagged with it.

Types

This section is empty.

Jump to

Keyboard shortcuts

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