log

package
v2.2.1 Latest Latest
Warning

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

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

Documentation

Overview

Package log provides utilities for attaching an slog.Logger configured with request-specific attributes to context.Context. The logger can later be retrieved or used indirectly through package-level logging function calls.

Server and client extension point implementations should use this package for generating logs instead of using other loggers or slog directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachFormatter added in v2.1.0

func AttachFormatter(inner slog.Handler, formatter TypeFormatter) slog.Handler

AttachFormatter wraps inner with a TypeFormatter that is applied to every attribute value of kind slog.KindAny (and recursively inside groups).

func AttachLogger

func AttachLogger(ctx context.Context, logger *slog.Logger) context.Context

AttachLogger creates a new Context with the provided Logger attached.

func Debug added in v2.1.0

func Debug(ctx context.Context, msg string, keyValArgs ...any)

Debug invokes DebugContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.

func DefaultA2ATypeFormatter added in v2.1.0

func DefaultA2ATypeFormatter(val any) (slog.Value, bool)

DefaultA2ATypeFormatter is a TypeFormatter that formats a2a.Event types as concise structured groups containing only the fields most useful for operational logging.

func Enabled added in v2.1.0

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

Enabled checks if the slog.Logger associated with the provided Context is enabled for the given level.

func Error

func Error(ctx context.Context, msg string, err error, keyValArgs ...any)

Error invokes ErrorContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.

func Info

func Info(ctx context.Context, msg string, keyValArgs ...any)

Info invokes InfoContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.

func LoggerFrom

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

LoggerFrom returns the Logger associated with the context, or slog.Default() if no context-scoped logger is available.

func Warn

func Warn(ctx context.Context, msg string, keyValArgs ...any)

Warn invokes WarnContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.

func Write added in v2.1.0

func Write(ctx context.Context, level slog.Level, msg string, keyValArgs ...any)

Write invokes Write on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.

Types

type TypeFormatter added in v2.1.0

type TypeFormatter func(val any) (slog.Value, bool)

TypeFormatter inspects a value and returns a replacement slog.Value when it recognises the type. Returning false leaves the original value unchanged.

Jump to

Keyboard shortcuts

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