multi: add NewLogClosure in lnutils to avoid repetition
And replaces all usage of `logClosure` with `lnutils.LogClosure`.
This commit is contained in:
38 files changed
+103
-299
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -1004,7 +1005,7 @@ func (w *WebAPIEstimator) updateFeeEstimates() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("Received response from source: %s", newLogClosure(
|
||||
log.Debugf("Received response from source: %s", lnutils.NewLogClosure(
|
||||
func() string {
|
||||
resp, _ := json.Marshal(resp)
|
||||
return string(resp)
|
||||
|
||||
@@ -27,19 +27,3 @@ func DisableLog() {
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
log = logger
|
||||
}
|
||||
|
||||
// logClosure is used to provide a closure over expensive logging operations so
|
||||
// don't have to be performed when the logging level doesn't warrant it.
|
||||
type logClosure func() string
|
||||
|
||||
// String invokes the underlying function and returns the result.
|
||||
func (c logClosure) String() string {
|
||||
return c()
|
||||
}
|
||||
|
||||
// newLogClosure returns a new closure over a function that returns a string
|
||||
// which itself provides a Stringer interface so that it can be used with the
|
||||
// logging system.
|
||||
func newLogClosure(c func() string) logClosure {
|
||||
return logClosure(c)
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/labels"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
@@ -869,7 +870,7 @@ func (c *ChanCloser) ReceiveClosingSigned( //nolint:funlen
|
||||
// With the closing transaction crafted, we'll now broadcast it
|
||||
// to the network.
|
||||
chancloserLog.Infof("Broadcasting cooperative close tx: %v",
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(closeTx)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -23,19 +23,3 @@ func DisableLog() {
|
||||
func UseLogger(logger btclog.Logger) {
|
||||
chancloserLog = logger
|
||||
}
|
||||
|
||||
// logClosure is used to provide a closure over expensive logging operations
|
||||
// so they aren't performed when the logging level doesn't warrant it.
|
||||
type logClosure func() string
|
||||
|
||||
// String invokes the underlying function and returns the result.
|
||||
func (c logClosure) String() string {
|
||||
return c()
|
||||
}
|
||||
|
||||
// newLogClosure returns a new closure over a function that returns a string
|
||||
// which itself provides a Stringer interface so that it can be used with the
|
||||
// logging system.
|
||||
func newLogClosure(c func() string) logClosure {
|
||||
return logClosure(c)
|
||||
}
|
||||
+8
-7
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnutils"
|
||||
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
@@ -1869,7 +1870,7 @@ func (lc *LightningChannel) restoreCommitState(
|
||||
lc.localCommitChain.addCommitment(localCommit)
|
||||
|
||||
lc.log.Tracef("starting local commitment: %v",
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(lc.localCommitChain.tail())
|
||||
}),
|
||||
)
|
||||
@@ -1885,7 +1886,7 @@ func (lc *LightningChannel) restoreCommitState(
|
||||
lc.remoteCommitChain.addCommitment(remoteCommit)
|
||||
|
||||
lc.log.Tracef("starting remote commitment: %v",
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(lc.remoteCommitChain.tail())
|
||||
}),
|
||||
)
|
||||
@@ -1920,7 +1921,7 @@ func (lc *LightningChannel) restoreCommitState(
|
||||
lc.remoteCommitChain.addCommitment(pendingRemoteCommit)
|
||||
|
||||
lc.log.Debugf("pending remote commitment: %v",
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(lc.remoteCommitChain.tip())
|
||||
}),
|
||||
)
|
||||
@@ -3245,9 +3246,9 @@ func (lc *LightningChannel) fetchParent(entry *PaymentDescriptor,
|
||||
return nil, fmt.Errorf("unable to find parent entry "+
|
||||
"%d in %v update log: %v\nUpdatelog: %v",
|
||||
entry.ParentIndex, logName,
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(entry)
|
||||
}), newLogClosure(func() string {
|
||||
}), lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(updateLog)
|
||||
}),
|
||||
)
|
||||
@@ -4249,7 +4250,7 @@ func (lc *LightningChannel) SignNextCommitment() (*NewCommitState, error) {
|
||||
"their_balance=%v, commit_tx: %v",
|
||||
newCommitView.ourBalance,
|
||||
newCommitView.theirBalance,
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(newCommitView.txn)
|
||||
}),
|
||||
)
|
||||
@@ -5209,7 +5210,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSigs *CommitSigs) error {
|
||||
lc.log.Tracef("local chain: our_balance=%v, "+
|
||||
"their_balance=%v, commit_tx: %v",
|
||||
localCommitmentView.ourBalance, localCommitmentView.theirBalance,
|
||||
newLogClosure(func() string {
|
||||
lnutils.NewLogClosure(func() string {
|
||||
return spew.Sdump(localCommitmentView.txn)
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -36,19 +36,3 @@ func UseLogger(logger btclog.Logger) {
|
||||
chain.UseLogger(logger)
|
||||
chainfee.UseLogger(logger)
|
||||
}
|
||||
|
||||
// logClosure is used to provide a closure over expensive logging operations
|
||||
// so don't have to be performed when the logging level doesn't warrant it.
|
||||
type logClosure func() string
|
||||
|
||||
// String invokes the underlying function and returns the result.
|
||||
func (c logClosure) String() string {
|
||||
return c()
|
||||
}
|
||||
|
||||
// newLogClosure returns a new closure over a function that returns a string
|
||||
// which itself provides a Stringer interface so that it can be used with the
|
||||
// logging system.
|
||||
func newLogClosure(c func() string) logClosure {
|
||||
return logClosure(c)
|
||||
}
|
||||
Reference in new issue
Block a user