github.com/decred/dcrlnd@v0.7.6/lnwallet/log.go (about) 1 package lnwallet 2 3 import ( 4 "github.com/decred/dcrlnd/build" 5 "github.com/decred/dcrlnd/lnwallet/chainfee" 6 "github.com/decred/slog" 7 ) 8 9 // walletLog is a logger that is initialized with no output filters. This 10 // means the package will not perform any logging by default until the caller 11 // requests it. 12 var walletLog slog.Logger 13 14 // The default amount of logging is none. 15 func init() { 16 UseLogger(build.NewSubLogger("LNWL", nil)) 17 } 18 19 // DisableLog disables all library log output. Logging output is disabled 20 // by default until UseLogger is called. 21 func DisableLog() { 22 UseLogger(slog.Disabled) 23 } 24 25 // UseLogger uses a specified Logger to output package logging info. 26 // This should be used in preference to SetLogWriter if the caller is also 27 // using slog. 28 func UseLogger(logger slog.Logger) { 29 walletLog = logger 30 chainfee.UseLogger(logger) 31 } 32 33 // logClosure is used to provide a closure over expensive logging operations 34 // so don't have to be performed when the logging level doesn't warrant it. 35 type logClosure func() string 36 37 // String invokes the underlying function and returns the result. 38 func (c logClosure) String() string { 39 return c() 40 } 41 42 // newLogClosure returns a new closure over a function that returns a string 43 // which itself provides a Stringer interface so that it can be used with the 44 // logging system. 45 func newLogClosure(c func() string) logClosure { 46 return logClosure(c) 47 }