log icon indicating copy to clipboard operation
log copied to clipboard

support log/slog.LogValuer

Open xuxife opened this issue 1 year ago • 0 comments

current logger didn't support log/slog.LogValuer, rather just a.Value.String() should a.Value.Resolve to respect interface LogValuer

// Handle handles the Record. It will only be called if Enabled returns true.
//
// Implements slog.Handler.
func (l *Logger) Handle(_ context.Context, record slog.Record) error {
	fields := make([]interface{}, 0, record.NumAttrs()*2)
	record.Attrs(func(a slog.Attr) bool {
		fields = append(fields, a.Key, a.Value.String())        <- a.Value.String()
		return true
	})

xuxife avatar Dec 05 '23 15:12 xuxife