github.com/decred/dcrlnd@v0.7.6/lnwallet/chancloser/log.go (about)

     1  package chancloser
     2  
     3  import (
     4  	"github.com/decred/dcrlnd/build"
     5  	"github.com/decred/slog"
     6  )
     7  
     8  // chancloserLog is a logger that is initialized with the slog.Disabled
     9  // logger.
    10  var chancloserLog slog.Logger
    11  
    12  // The default amount of logging is none.
    13  func init() {
    14  	UseLogger(build.NewSubLogger("CHCL", nil))
    15  }
    16  
    17  // DisableLog disables all logging output.
    18  func DisableLog() {
    19  	UseLogger(slog.Disabled)
    20  }
    21  
    22  // UseLogger uses a specified Logger to output package logging info.
    23  func UseLogger(logger slog.Logger) {
    24  	chancloserLog = logger
    25  }
    26  
    27  // logClosure is used to provide a closure over expensive logging operations
    28  // so they aren't performed when the logging level doesn't warrant it.
    29  type logClosure func() string
    30  
    31  // String invokes the underlying function and returns the result.
    32  func (c logClosure) String() string {
    33  	return c()
    34  }
    35  
    36  // newLogClosure returns a new closure over a function that returns a string
    37  // which itself provides a Stringer interface so that it can be used with the
    38  // logging system.
    39  func newLogClosure(c func() string) logClosure {
    40  	return logClosure(c)
    41  }