github.com/decred/dcrlnd@v0.7.6/lnrpc/invoicesrpc/log.go (about)

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