github.com/decred/dcrlnd@v0.7.6/contractcourt/log.go (about) 1 package contractcourt 2 3 import ( 4 "github.com/decred/dcrlnd/build" 5 "github.com/decred/slog" 6 ) 7 8 var ( 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 log slog.Logger 13 14 // brarLog is the logger used by the breach arb. 15 brarLog slog.Logger 16 17 // utxnLog is the logger used by the utxo nursary. 18 utxnLog slog.Logger 19 ) 20 21 // The default amount of logging is none. 22 func init() { 23 UseLogger(build.NewSubLogger("CNCT", nil)) 24 UseBreachLogger(build.NewSubLogger("BRAR", nil)) 25 UseNurseryLogger(build.NewSubLogger("UTXN", nil)) 26 } 27 28 // DisableLog disables all library log output. Logging output is disabled 29 // by default until UseLogger is called. 30 func DisableLog() { 31 UseLogger(slog.Disabled) 32 } 33 34 // UseLogger uses a specified Logger to output package logging info. 35 // This should be used in preference to SetLogWriter if the caller is also 36 // using slog. 37 func UseLogger(logger slog.Logger) { 38 log = logger 39 } 40 41 // UseBreachLogger uses a specified Logger to output package logging info. 42 // This should be used in preference to SetLogWriter if the caller is also 43 // using btclog. 44 func UseBreachLogger(logger slog.Logger) { 45 brarLog = logger 46 47 } 48 49 // UseNurseryLogger uses a specified Logger to output package logging info. 50 // This should be used in preference to SetLogWriter if the caller is also 51 // using btclog. 52 func UseNurseryLogger(logger slog.Logger) { 53 utxnLog = logger 54 55 } 56 57 // logClosure is used to provide a closure over expensive logging operations so 58 // don't have to be performed when the logging level doesn't warrant it. 59 type logClosure func() string 60 61 // String invokes the underlying function and returns the result. 62 func (c logClosure) String() string { 63 return c() 64 } 65 66 // newLogClosure returns a new closure over a function that returns a string 67 // which itself provides a Stringer interface so that it can be used with the 68 // logging system. 69 func newLogClosure(c func() string) logClosure { 70 return logClosure(c) 71 }