-
Release v1.0.0 Stable
released this
2026-05-11 18:51:47 -06:00 | 1 commits to main since this releasev1.0.0
code.nochebuena.dev/go/logzOverview
logzv1.0.0 commits the structured logging API as stable. All v0.9.0 roadmap
items are resolved. The module ships a minimal six-methodLoggerinterface
backed by stdliblog/slog, with zero external dependencies, owned context keys
for request correlation, and a duck-typedxerrorsenrichment bridge validated
under concurrent production load.What Changed Since v0.9.0
New:
Options.Writer io.Writertype Options struct { Level slog.Level JSON bool StaticArgs []any Writer io.Writer // nil → os.Stdout }The output destination is now configurable. When
Writeris nil the behavior is
identical to v0.9.0 (writes toos.Stdout). Anyio.Writerimplementation is
accepted:// Test log capture var buf bytes.Buffer l := logz.New(logz.Options{Writer: &buf}) // File-based audit trail f, _ := os.OpenFile("audit.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) l := logz.New(logz.Options{Writer: f, JSON: true}) // Both stdout and file l := logz.New(logz.Options{Writer: io.MultiWriter(os.Stdout, f), JSON: true})Roadmap items resolved
Item Resolution io.Writerconfigurable✅ Options.Writer— nil defaults toos.StdoutLog sampling ❌ No — belongs in slog.Handlerwrappers or the observability layerConcurrent xerrors enrichment ✅ Validated — ErrorContext()is read-only post-constructionLoggerinterface is final✅ Committed — 6 methods; Fatal/Panicintentionally excludedWithFieldsmerge concurrency✅ Validated — context.WithValueimmutability guarantees safetyFull API (stable)
Logger— interface:Debug,Info,Warn,Error(msg, err, args...),
With(args...) Logger,WithContext(ctx) Logger.Options—Level slog.Level,JSON bool,StaticArgs []any,
Writer io.Writer(nil →os.Stdout). Zero value is valid.New(opts Options) Logger— constructor; returnsLogger, never the concrete type.WithRequestID(ctx, id) context.Context— stores a correlation ID under this
package's private context key.GetRequestID(ctx) string— retrieves the ID; returns""if absent or ctx nil.WithField(ctx, key, value) context.Context— adds a single field to the context.WithFields(ctx, fields) context.Context— merges multiple fields; does not
overwrite existing keys.Logger.WithContext(ctx) Logger— child logger pre-enriched withrequest_id
and any extra fields from the context; returns the same logger if ctx carries no
relevant values.Automatic error enrichment —
Logger.ErrorinspectserrforErrorCode()
andErrorContext()duck-type methods (satisfied by*xerrors.Err) and appends
error_codeand context fields automatically. No import betweenlogzand
xerrorsis required in either direction.Migration from v0.9.0
No breaking changes.
Options{}continues to write toos.Stdout.go get code.nochebuena.dev/go/logz@v1.0.0Downloads