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 ¶
- func AttachFormatter(inner slog.Handler, formatter TypeFormatter) slog.Handler
- func AttachLogger(ctx context.Context, logger *slog.Logger) context.Context
- func Debug(ctx context.Context, msg string, keyValArgs ...any)
- func DefaultA2ATypeFormatter(val any) (slog.Value, bool)
- func Enabled(ctx context.Context, level slog.Level) bool
- func Error(ctx context.Context, msg string, err error, keyValArgs ...any)
- func Info(ctx context.Context, msg string, keyValArgs ...any)
- func LoggerFrom(ctx context.Context) *slog.Logger
- func Warn(ctx context.Context, msg string, keyValArgs ...any)
- func Write(ctx context.Context, level slog.Level, msg string, keyValArgs ...any)
- type TypeFormatter
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 ¶
AttachLogger creates a new Context with the provided Logger attached.
func Debug ¶ added in v2.1.0
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
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
Enabled checks if the slog.Logger associated with the provided Context is enabled for the given level.
func Error ¶
Error invokes ErrorContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.
func Info ¶
Info invokes InfoContext on the slog.Logger associated with the provided Context or slog.Default() if no context-scoped logger is available.
func LoggerFrom ¶
LoggerFrom returns the Logger associated with the context, or slog.Default() if no context-scoped logger is available.
func Warn ¶
Warn invokes WarnContext 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
TypeFormatter inspects a value and returns a replacement slog.Value when it recognises the type. Returning false leaves the original value unchanged.