multi: add SpewLogClosure to avoid code repetition

This commit is contained in:
yyforyongyu committed 2024-07-25 22:18:49 +08:00
1 parent b6049ff94b
commit d992cf94d6
19 files changed
+57 -144

No files matched your search

+10
View File
@@ -1,5 +1,7 @@
package lnutils
import "github.com/davecgh/go-spew/spew"
// 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
@@ -15,3 +17,11 @@ func (c LogClosure) String() string {
func NewLogClosure(c func() string) LogClosure {
return LogClosure(c)
}
// SpewLogClosure takes an interface and returns the string of it created from
// `spew.Sdump` in a LogClosure.
func SpewLogClosure(a any) LogClosure {
return func() string {
return spew.Sdump(a)
}
}