diff --git a/lnutils/log.go b/lnutils/log.go index a588bf3ce..87057290b 100644 --- a/lnutils/log.go +++ b/lnutils/log.go @@ -1,8 +1,11 @@ package lnutils import ( + "log/slog" "strings" + "github.com/btcsuite/btcd/btcec/v2" + "github.com/btcsuite/btclog/v2" "github.com/davecgh/go-spew/spew" ) @@ -36,3 +39,14 @@ func NewSeparatorClosure() LogClosure { return strings.Repeat("=", 80) } } + +// LogPubKey returns a slog attribute for logging a public key in hex format. +func LogPubKey(key string, pubKey *btcec.PublicKey) slog.Attr { + // Handle nil pubkey gracefully, although callers should ideally prevent + // this. + if pubKey == nil { + return btclog.Fmt(key, "") + } + + return btclog.Hex6(key, pubKey.SerializeCompressed()) +}