mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 14:40:51 +02:00
lnutil: add LogPubKey helper function
This captures a common pattern where we want to log a peer's public key along side each logging statement.
This commit is contained in:
@@ -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, "<nil>")
|
||||
}
|
||||
|
||||
return btclog.Hex6(key, pubKey.SerializeCompressed())
|
||||
}
|
||||
|
Reference in New Issue
Block a user