github.com/btcsuite/btcwallet/walletdb@v1.4.2/migration/log.go (about)

     1  package migration
     2  
     3  import "github.com/btcsuite/btclog"
     4  
     5  // log is a logger that is initialized with no output filters.  This
     6  // means the package will not perform any logging by default until the caller
     7  // requests it.
     8  var log btclog.Logger
     9  
    10  // The default amount of logging is none.
    11  func init() {
    12  	DisableLog()
    13  }
    14  
    15  // DisableLog disables all library log output.  Logging output is disabled
    16  // by default until either UseLogger or SetLogWriter are called.
    17  func DisableLog() {
    18  	UseLogger(btclog.Disabled)
    19  }
    20  
    21  // UseLogger uses a specified Logger to output package logging info.
    22  // This should be used in preference to SetLogWriter if the caller is also
    23  // using btclog.
    24  func UseLogger(logger btclog.Logger) {
    25  	log = logger
    26  }
    27  
    28  // LogClosure is a closure that can be printed with %v to be used to
    29  // generate expensive-to-create data for a detailed log level and avoid doing
    30  // the work if the data isn't printed.
    31  type logClosure func() string
    32  
    33  // String invokes the log closure and returns the results string.
    34  func (c logClosure) String() string {
    35  	return c()
    36  }
    37  
    38  // newLogClosure returns a new closure over the passed function which allows
    39  // it to be used as a parameter in a logging function that is only invoked when
    40  // the logging level is such that the message will actually be logged.
    41  func newLogClosure(c func() string) logClosure {
    42  	return logClosure(c)
    43  }