2021-07-07 03:39:56 +02:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/btcsuite/btclog"
|
|
|
|
)
|
|
|
|
|
|
|
|
// log is a logger that is initialized with no output filters. This
|
|
|
|
// means the package will not perform any logging by default until the caller
|
|
|
|
// requests it.
|
|
|
|
var log btclog.Logger
|
|
|
|
|
|
|
|
// The default amount of logging is none.
|
|
|
|
func init() {
|
|
|
|
DisableLog()
|
|
|
|
}
|
|
|
|
|
|
|
|
// DisableLog disables all library log output. Logging output is disabled
|
|
|
|
// by default until either UseLogger or SetLogWriter are called.
|
|
|
|
func DisableLog() {
|
|
|
|
log = btclog.Disabled
|
|
|
|
}
|
|
|
|
|
|
|
|
// UseLogger uses a specified Logger to output package logging info.
|
|
|
|
// This should be used in preference to SetLogWriter if the caller is also
|
|
|
|
// using btclog.
|
|
|
|
func UseLogger(logger btclog.Logger) {
|
|
|
|
log = logger
|
|
|
|
}
|
|
|
|
|
2022-06-14 19:06:45 +02:00
|
|
|
func GetLogger() btclog.Logger {
|
|
|
|
return log
|
|
|
|
}
|
|
|
|
|
2021-07-07 03:39:56 +02:00
|
|
|
var loggedStrings = map[string]bool{} // is this gonna get too large?
|
|
|
|
var loggedStringsMutex sync.Mutex
|
|
|
|
|
|
|
|
func LogOnce(s string) {
|
|
|
|
loggedStringsMutex.Lock()
|
|
|
|
defer loggedStringsMutex.Unlock()
|
|
|
|
if loggedStrings[s] {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
loggedStrings[s] = true
|
|
|
|
log.Info(s)
|
|
|
|
}
|
|
|
|
|
2022-06-14 19:06:45 +02:00
|
|
|
func Log(s string) {
|
|
|
|
log.Info(s)
|
|
|
|
}
|
|
|
|
|
2021-07-07 03:39:56 +02:00
|
|
|
func Warn(s string) {
|
|
|
|
log.Warn(s)
|
|
|
|
}
|