Files
logz/CHANGELOG.md
Rene Nochebuena 05c99f72ff feat(logz)!: promote to v1.0.0 — configurable io.Writer output destination
Add Writer io.Writer field to Options; when nil, defaults to os.Stdout (no
breaking change). Enables log capture in tests via the public API and supports
writing to files, multi-writers, or any io.Writer implementation in production.
All remaining roadmap items validated in production (xerrors enrichment
concurrency, WithFields merge semantics, Logger interface finality). API
committed as stable.
2026-05-11 18:50:37 -06:00

3.4 KiB

Changelog

All notable changes to this module will be documented in this file.

The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.

1.0.0 — 2026-05-12

Added

  • Options.Writer io.Writer — configurable output destination; nil defaults to os.Stdout (backward-compatible). Accepts any io.Writer implementation: *os.File, bytes.Buffer, io.MultiWriter, custom sinks, etc.

Unchanged

All existing API (Logger, New, WithRequestID, GetRequestID, WithField, WithFields) is API-compatible with v0.9.0.

0.9.0 - 2026-03-18

Added

  • Logger interface — Debug(msg string, args ...any), Info(msg string, args ...any), Warn(msg string, args ...any), Error(msg string, err error, args ...any), With(args ...any) Logger, WithContext(ctx context.Context) Logger
  • Options struct — Level slog.Level (minimum log level; default slog.LevelInfo), JSON bool (JSON vs text output; default text), StaticArgs []any (key-value pairs attached to every record); zero value is valid
  • New(opts Options) Logger — constructs a Logger backed by log/slog, writing to os.Stdout; returns the Logger interface, never the concrete type
  • WithRequestID(ctx context.Context, id string) context.Context — stores a request correlation ID in the context under a private unexported key owned by this package
  • GetRequestID(ctx context.Context) string — retrieves the correlation ID; returns "" if absent or if ctx is nil
  • WithField(ctx context.Context, key string, value any) context.Context — adds a single key-value logging field to the context
  • WithFields(ctx context.Context, fields map[string]any) context.Context — merges multiple key-value fields into the context without overwriting existing fields
  • Logger.WithContext(ctx context.Context) Logger — returns a child logger pre-enriched with request_id and any extra fields stored in the context via WithRequestID / WithField / WithFields; returns the same logger unchanged if ctx is nil or carries no relevant values
  • Logger.With(args ...any) Logger — returns a child logger with the given key-value attributes permanently attached to every subsequent record
  • Automatic error_code field enrichment in Logger.Error when err satisfies the private errorWithCode duck-type interface (ErrorCode() string)
  • Automatic context-field enrichment in Logger.Error when err satisfies the private errorWithContext duck-type interface (ErrorContext() map[string]any)

Design Notes

  • New returns the Logger interface (not *slogLogger), and With likewise returns Logger; the concrete type is never exported, making the interface the only public surface and enabling safe local re-declaration in downstream libraries without importing this package.
  • This package owns the context keys ctxRequestIDKey{} and ctxExtraFieldsKey{} as unexported struct types, preventing collisions; any module that needs to attach a request ID to logs imports only logz.
  • The xerrors integration is zero-import: Logger.Error uses errors.As against two private interfaces (errorWithCode, errorWithContext) that xerrors.Err satisfies — no import between the two packages is required in either direction.