github.com/lbryio/lbcd@v0.22.119/claimtrie/node/log.go (about)

     1  package node
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/btcsuite/btclog"
     7  )
     8  
     9  // log 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 log btclog.Logger
    13  
    14  // The default amount of logging is none.
    15  func init() {
    16  	DisableLog()
    17  }
    18  
    19  // DisableLog disables all library log output.  Logging output is disabled
    20  // by default until either UseLogger or SetLogWriter are called.
    21  func DisableLog() {
    22  	log = btclog.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 btclog.
    28  func UseLogger(logger btclog.Logger) {
    29  	log = logger
    30  }
    31  
    32  func GetLogger() btclog.Logger {
    33  	return log
    34  }
    35  
    36  var loggedStrings = map[string]bool{} // is this gonna get too large?
    37  var loggedStringsMutex sync.Mutex
    38  
    39  func LogOnce(s string) {
    40  	loggedStringsMutex.Lock()
    41  	defer loggedStringsMutex.Unlock()
    42  	if loggedStrings[s] {
    43  		return
    44  	}
    45  	loggedStrings[s] = true
    46  	log.Info(s)
    47  }
    48  
    49  func Log(s string) {
    50  	log.Info(s)
    51  }
    52  
    53  func Warn(s string) {
    54  	log.Warn(s)
    55  }