diff --git a/v2/attrs.go b/v2/attrs.go index 5a0fee9..471aa25 100644 --- a/v2/attrs.go +++ b/v2/attrs.go @@ -32,6 +32,11 @@ func Hex2(key string, value []byte) slog.Attr { // HexN is a convenience function for hex-encoded log attributes which prints // a maximum of n bytes. func HexN(key string, value []byte, n uint) slog.Attr { + // Handle nil slice gracefully. + if value == nil { + return slog.String(key, "") + } + if len(value) <= int(n) { return slog.String(key, hex.EncodeToString(value)) }