Skip to content

Commit 1befe8e

Browse files
committed
lnutils: Add logging helper for byte slices
LogBytesPreview returns a slog attribute that shows a hex preview of the given byte slice. The result is truncated for readability. The preview length is fixed to avoid leaking full binary payloads in logs while still allowing identification of the data.
1 parent 0fdb433 commit 1befe8e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lnutils/log.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,16 @@ func LogPubKey(key string, pubKey *btcec.PublicKey) slog.Attr {
5050

5151
return btclog.Hex6(key, pubKey.SerializeCompressed())
5252
}
53+
54+
// LogBytesPreview returns a slog attribute that shows a hex preview
55+
// of the given byte slice. The result is truncated for readability.
56+
// The preview length is fixed to avoid leaking full binary payloads
57+
// in logs while still allowing identification of the data.
58+
func LogBytesPreview(key string, data []byte) slog.Attr {
59+
// Handle nil slice gracefully.
60+
if data == nil {
61+
return btclog.Fmt(key, "<nil>")
62+
}
63+
64+
return btclog.Hex6(key, data)
65+
}

0 commit comments

Comments
 (0)