zap icon indicating copy to clipboard operation
zap copied to clipboard

zap.Any should explicitly support slog.Attr and slog.LogValuer

Open oakad opened this issue 7 months ago • 0 comments

Ext/zapslog allows one to use zap as "backend" in slog enabled apps.

However, it is possible, that some library has objects implementing slog.LogValuer while main app is using zap as is. In such situations it will be convenient to pass the LogValuer objects to zap.Any and rely on it performing the same sort of conversion zapslog does.

slog.Attr can appear in similar scenarios. For example, a "rich" error object can be annotated with some attrs.

Even if application as a whole sticks to zap, slog being part of standard library makes it convenient to use slog.Attr in all kinds of corners and so it makes sense for zap to support it a bit better. Possibly even offer a specialisation of CheckedEntry.Write which takes slog.Attr directly (something like CheckedEntry.WriteAttrs).

oakad avatar Apr 29 '25 07:04 oakad