github.com/BlockABC/godash@v0.0.0-20191112120524-f4aa3a32c566/txscript/log.go (about) 1 // Copyright (c) 2013-2015 The btcsuite developers 2 // Copyright (c) 2016 The Dash developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package txscript 7 8 import ( 9 "errors" 10 "io" 11 12 "github.com/btcsuite/btclog" 13 ) 14 15 // log is a logger that is initialized with no output filters. This 16 // means the package will not perform any logging by default until the caller 17 // requests it. 18 var log btclog.Logger 19 20 // The default amount of logging is none. 21 func init() { 22 DisableLog() 23 } 24 25 // DisableLog disables all library log output. Logging output is disabled 26 // by default until either UseLogger or SetLogWriter are called. 27 func DisableLog() { 28 log = btclog.Disabled 29 } 30 31 // UseLogger uses a specified Logger to output package logging info. 32 // This should be used in preference to SetLogWriter if the caller is also 33 // using btclog. 34 func UseLogger(logger btclog.Logger) { 35 log = logger 36 } 37 38 // SetLogWriter uses a specified io.Writer to output package logging info. 39 // This allows a caller to direct package logging output without needing a 40 // dependency on seelog. If the caller is also using btclog, UseLogger should 41 // be used instead. 42 func SetLogWriter(w io.Writer, level string) error { 43 if w == nil { 44 return errors.New("nil writer") 45 } 46 47 UseLogger(btclog.Disabled) 48 return nil 49 } 50 51 // LogClosure is a closure that can be printed with %v to be used to 52 // generate expensive-to-create data for a detailed log level and avoid doing 53 // the work if the data isn't printed. 54 type logClosure func() string 55 56 func (c logClosure) String() string { 57 return c() 58 } 59 60 func newLogClosure(c func() string) logClosure { 61 return logClosure(c) 62 }